https://codeforces.com/contest/1185/problem/E
题意:在矩阵上,用a~z代表,然后后来画的可以覆盖掉之前画的,问可行方法是怎么画的
1 #include<bits/stdc++.h> 2 using namespace std; 3 const int M=2200; 4 int x1[27],x2[27],y[27],yy[27]; 5 char fir[M][M],sec[M][M]; 6 7 8 int main(){ 9 int t; 10 ios::sync_with_stdio(false); 11 cin>>t; 12 while(t--){ 13 int n,m; 14 cin>>n>>m; 15 for(int i=1;i<=26;i++) 16 x1[i]=x2[i]=y[i]=yy[i]=0; 17 int maxx=0; 18 for(int i=1;i<=n;i++) 19 for(int j=1;j<=m;j++){ 20 cin>>fir[i][j]; 21 int x=fir[i][j]-'a'+1; 22 sec[i][j]='.'; 23 if(fir[i][j]=='.') 24 continue; 25 maxx=max(maxx,x); 26 if(x1[x]==0) 27 x1[x]=i,y[x]=j; 28 x2[x]=i,yy[x]=j; 29 } 30 if(maxx==0){ 31 cout<<"YES"<<endl; 32 cout<<"0"<<endl; 33 continue; 34 } 35 int flag=0; 36 for(int i=1;i<=maxx;i++){ 37 if(x1[i]==0) 38 x1[i]=x2[i]=x1[maxx],y[i]=yy[i]=y[maxx]; 39 if(x1[i]!=x2[i]&&y[i]!=yy[i]){ 40 flag=1; 41 break; 42 } 43 for(int j=x1[i];j<=x2[i];j++) 44 for(int k=y[i];k<=yy[i];k++) 45 sec[j][k]='a'+i-1; 46 } 47 if(flag){ 48 cout<<"NO"<<endl; 49 continue; 50 } 51 for(int i=1;i<=n;i++){ 52 for(int j=1;j<=m;j++) 53 if(fir[i][j]!=sec[i][j]){ 54 flag=1; 55 break; 56 } 57 if(flag) 58 break; 59 } 60 if(flag){ 61 cout<<"NO"<<endl; 62 continue; 63 } 64 cout<<"YES"<<endl; 65 cout<<maxx<<endl; 66 for(int i=1;i<=26;i++){ 67 if(x1[i]==0) 68 break; 69 cout<<x1[i]<<" "<<y[i]<<" "<<x2[i]<<" "<<yy[i]<<endl; 70 71 72 } 73 74 } 75 return 0; 76 }