http://acm.hdu.edu.cn/showproblem.php?pid=3262
Meaning of the questions: accounting location must continuously find the most comfortable value left in this condition maximum (because of their own to sit)
If you account for less than p continuous then there is only an own position
Account for less than output -1
Solution: it is simple for loop line by line, looking past a row there (the number of columns - the number of successive positions +1 to account for the) kind of continuous, each investigation in the past if we are all empty position can be accounted for, but also to set up maxx found maximum
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#include<bits/stdc++.h> using namespace std; struct node { int idd,time,h,m,q; }a[55]; bool cmp(node x,node y) { return x.time<y.time; } int mp[55][55]; int main() { int i,j,n,m,k; while(scanf("%d%d%d",&n,&m,&k),n||m||k) { memset(mp,-1,sizeof(mp)); for(i=1;i<=n;i++) { for(j=1;j<=m;j++) { scanf("%d",&mp[i][j]); } } for(i=1;i<=k;i++) { scanf("%d:%d %d",&a[i].h,&a[i].m,&a[i].q); a[i].idd=i; a[i].time=a[i].h*60+a[i].m; } sort(a+1, A + . 1 + K, CMP); // Note After sorting output to the original input sequentially outputs Vector < int > VE [ 55 ]; for (I = . 1 ; I <= K; I ++ ) { int P = A [I ] .q; int Maxx = - 0x3f3f3f3f ; int maxydw1 = 0 , maxydw2 = 0 ; for (J = . 1 ; J <= n-; J ++ ) { int GS = m-P + . 1 ; for ( int O = . 1 ; O < = gs; o ++) { Int F = . 1 ; for ( int Ql = O; Ql <= p-O + . 1 ; Ql ++) // start wrong here for a long time { IF (MP [J] [Ql] == - . 1 ) F = 0 ; } IF (F == . 1 && MP [J] [O]> Maxx) { Maxx = MP [J] [O]; maxydw1 = J; maxydw2 = O; } } } if(maxydw1!=0) { int po=maxydw2+p-1; for(int o=maxydw2;o<=po;o++) { mp[maxydw1][o]=-1; } ve[a[i].idd].push_back(maxydw1); ve[a[i].idd].push_back(maxydw2); } else { int mx=0,my=0,maxxx=-0x3f3f3f3f; for(int q1=1;q1<=n;q1++) { for(int q2=1;q2<=m;q2++) { if(mp[q1][q2]!=-1&&mp[q1][q2]>maxxx) { maxxx=mp[q1][q2]; mx=q1,my=q2; } } } if(mx!=0)ve[a[i].idd].push_back(mx),ve[a[i].idd].push_back(my),mp[mx][my]=-1; else ve[a[i].idd].push_back(-1); } } for(i=1;i<=k;i++) { if(ve[i].size()==1)cout<<-1<<endl; else cout<<ve[i][0]<<" "<<ve[i][1]<<endl; } } return 0; }