这个用的就是死模拟,变换形式实际上只有两种: 1. 顺时针旋转90度 2.镜面对称
另外发现 模板template很好用。
1 /*
2 ID: 31440461
3 LANG: C++
4 TASK: transform
5 */
6 #include<iostream>
7 using namespace std;
8 typedef char arr[11][11];
9 arr pat1,pat2,bak;
10 int n;
11
12 template <class T>
13 void init(T& a)
14 {
15 for (int i=0;i<n;i++)
16 for (int j=0;j<n;j++)
17 cin >> a[i][j];
18 }
19
20 template <class T>
21 void eva(const T& a,T& b)
22 {
23 for (int i=0;i<n;i++)
24 for (int j=0;j<n;j++)
25 b[i][j] = a[i][j];
26 }
27
28 template <class T>
29 bool cmp(const T& a,const T& b)
30 {
31 for (int i=0;i<n;i++)
32 for (int j=0;j<n;j++)
33 if (a[i][j] != b[i][j]) return 0;
34 return 1;
35 }
36
37 void tranf1()
38 {
39 arr tmp;
40 eva(pat1,tmp);
41 for (int i=0;i<n;i++)
42 for (int j=0;j<n;j++)
43 pat1[j][n-1-i] = tmp[i][j];
44 }
45
46 void tranf4()
47 {
48 arr tmp;
49 eva(pat1,tmp);
50 for (int i=0;i<n;i++)
51 for (int j=0;j<n;j++)
52 pat1[i][n-1-j] = tmp[i][j];
53 }
54
55 int main()
56 {
57 freopen ("transform.in","r",stdin);
58 freopen ("transform.out","w",stdout);
59 cin >> n;
60 init(pat1);
61 init(pat2);
62 eva(pat1,bak);
63 tranf1();
64 if (cmp(pat1,pat2)) { cout << 1 << endl; return 0;}
65 tranf1();
66 if (cmp(pat1,pat2)) { cout << 2 << endl; return 0;}
67 tranf1();
68 if (cmp(pat1,pat2)) { cout << 3 << endl; return 0;}
69 tranf1();
70 tranf4();
71 if (cmp(pat1,pat2)) { cout << 4 << endl; return 0;}
72 for (int i=0;i<3;i++){
73 tranf1();
74 if (cmp(pat1,pat2)) { cout << 5 << endl; return 0;}
75 }
76 if (cmp(pat1,pat2)) { cout << 6 << endl; return 0;}
77 cout << 7 << endl;
78 return 0;
79 }
80