标签:des blog http io ar os sp for div
Description
Input
Output
Sample Input
Sample Output
#include <cstdio> #include <cstdlib> #include <iostream> #include <cstring> #include <algorithm> using namespace std; const int maxn=40; const int maxq=60; int graph[maxn][maxn]; bool flag[maxn][maxn]; int n,m,k; struct quest { int time,num,q; int x,y; } P[maxq]; bool cmp1(quest A,quest B) { return A.time<B.time; } bool cmp2(quest A,quest B) { return A.num<B.num; } void solve(quest &kk) { int ax,ay,sx,sy,cnt; ax=ay=sx=sy=-1; for(int i=0;i<n;i++){ for(int j=0;j<m;j++){ if(flag[i][j]) continue; cnt=0; if((ax==-1&&ay==-1)||(graph[i][j]>graph[ax][ay])){ ax=i; ay=j; } for(int k=j;k<m;k++){ if(flag[i][k]) break; else cnt++; } if(cnt>=kk.q){ if((sx==-1&&sy==-1)||(graph[i][j]>graph[sx][sy])){ sx=i; sy=j; } } } } if(sx==-1&&sy==-1){ kk.x=ax; kk.y=ay; if(kk.x!=-1) flag[kk.x][kk.y]=1; } else{ kk.x=sx; kk.y=sy; for(int i=0;i<kk.q;i++) flag[kk.x][kk.y+i]=1; } } int main() { char cc[20]; int tt,num1,num2,ll; while(scanf("%d%d%d",&n,&m,&k),n!=0||m!=0||k!=0){ for(int i=0;i<n;i++) for(int j=0;j<m;j++) scanf("%d",&graph[i][j]); memset(flag,0,sizeof(flag)); for(int i=0;i<k;i++){ scanf("%s %d",cc,&tt); P[i].num=i; P[i].q=tt; ll=strlen(cc); if(cc[2]==‘:‘){ num1=((cc[0]-‘0‘)*10+(cc[1]-‘0‘))*60; if(ll-3>=2) num2=(cc[3]-‘0‘)*10+(cc[4]-‘0‘); else num2=cc[3]-‘0‘; } else{ num1=(cc[0]-‘0‘)*60; if(ll-2>=2) num2=(cc[2]-‘0‘)*10+(cc[3]-‘0‘); else num2=cc[2]-‘0‘; } P[i].time=num1+num2; } sort(P,P+k,cmp1); for(int i=0;i<k;i++) solve(P[i]); sort(P,P+k,cmp2); for(int i=0;i<k;i++){ if(P[i].x==-1) printf("-1\n"); else printf("%d %d\n",P[i].x+1,P[i].y+1); } } return 0; }
hdu 3262 09 宁波 现场 C - Seat taking up is tough 暴力
标签:des blog http io ar os sp for div
原文地址:http://www.cnblogs.com/xuesu/p/4089999.html