这题挺水,看懂了,就OK。卡了几下内存,还是卡过了。
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 #include <queue> 5 #include <map> 6 #include <ctime> 7 #include <cmath> 8 #include <algorithm> 9 using namespace std; 10 #define N 1403 11 int r[N][N][2],c[N][N][2]; 12 int r1[N][N][2],c1[N][N][2]; 13 char str[N][N]; 14 int main() 15 { 16 int i,j,n,t; 17 scanf("%d",&n); 18 for(i = 0;i < n;i ++) 19 scanf("%s",str[i]); 20 for(i = 1;i <= n;i ++) 21 { 22 for(j = 1;j <= n;j ++) 23 { 24 t = str[i-1][j-1] == 's'?1:0; 25 r[i][j][t] = r[i-1][j][t] + 1; 26 c[i][j][t] = c[i][j-1][t] + 1; 27 r1[i][j][t] = r1[i-1][j-1][t] + 1; 28 c1[i][j][t] = c1[i-1][j+1][t] + 1; 29 r[i][j][t^1] = 0; 30 c[i][j][t^1] = 0; 31 r1[i][j][t^1] = 0; 32 c1[i][j][t^1] = 0; 33 } 34 } 35 int max1,max2; 36 max1 = max2 = 0; 37 for(i = 1;i <= n;i ++) 38 { 39 for(j = 1;j <= n;j ++) 40 { 41 t = str[i-1][j-1] == 's'?1:0; 42 if(t) 43 max1 = max(max1,max(max(r[i][j][1],c[i][j][1]),max(r1[i][j][1],c1[i][j][1]))); 44 else 45 max2 = max(max2,max(max(r[i][j][0],c[i][j][0]),max(r1[i][j][0],c1[i][j][0]))); 46 } 47 } 48 if(max1 > max2) 49 printf("s %d ",max1); 50 else if(max1 < max2) 51 printf("S %d ",max2); 52 else 53 printf("? %d ",max1); 54 return 0; 55 }