1. 程式人生 > >牛客網暑期ACM多校訓練營(第四場) F

牛客網暑期ACM多校訓練營(第四場) F

退出 targe using void pre .com 多重循環 break clu

參考:http://www.cnblogs.com/Jadon97/p/9383027.html

 1 #include <iostream>
 2 #include <cstdio>
 3 #include <cstring>
 4 #define N 2005
 5 using namespace std;
 6 int n,m,t;
 7 char tu[N][N];
 8 void test()
 9 {
10     int i;
11     for (i=0;i<n;i++)
12     {
13         for (int j=0;j<m;j++)
14 { 15 printf("%c",tu[i][j]); 16 } 17 printf("\n"); 18 } 19 } 20 void solve() 21 { 22 int i,p=0,q=0,r=0,ra=n-1,c=0,ca=m-1,flag=0;//從外圍向內遍歷找到不對稱的一行 23 for (r=0;r<ra;r++,ra--) 24 { 25 for (i=0;i<m;i++) 26 { 27 if (tu[r][i]!=tu[ra][i])//
用全局變量flag可以退出多重循環~ 28 { 29 flag=1; 30 break; 31 } 32 } 33 if (flag) 34 { 35 break; 36 } 37 } 38 if (r>=ra)//全對稱的情況 39 { 40 r--; 41 } 42 flag=0; 43 for (c=0;c<ca;c++,ca--)
44 { 45 for (i=0;i<n;i++) 46 { 47 if (tu[i][c]!=tu[i][ca]) 48 { 49 flag=1; 50 break; 51 } 52 } 53 if (flag) 54 { 55 break; 56 } 57 } 58 if (c>=ca) 59 { 60 c--; 61 } 62 printf("%d\n",r*c); 63 64 } 65 int main() 66 { 67 // freopen("總結.txt","r",stdin); 68 while (scanf("%d",&t)!=EOF) 69 { 70 while (t--) 71 { 72 scanf("%d %d",&n,&m); 73 int i; 74 for (i=0;i<n;i++) 75 { 76 scanf("%s",&tu[i]); 77 getchar(); 78 } 79 // test(); 80 solve(); 81 } 82 } 83 84 return 0; 85 }

牛客網暑期ACM多校訓練營(第四場) F