牛客网暑期ACM多校训练营(第四场) F

参考: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("
");
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
",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  }
原文地址:https://www.cnblogs.com/hemeiwolong/p/9384615.html