USACO 1.2 TRANSFORM

Transformations

A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into another square pattern. Write a program that will recognize the minimum transformation that has been applied to the original pattern given the following list of possible transformations:

  • #1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
  • #2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
  • #3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
  • #4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
  • #5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
  • #6: No Change: The original pattern was not changed.
  • #7: Invalid Transformation: The new pattern was not obtained by any of the above methods.

In the case that more than one transform could have been used, choose the one with the minimum number above.

PROGRAM NAME: transform

INPUT FORMAT

Line 1: A single integer, N
Line 2..N+1: N lines of N characters (each either `@' or `-'); this is the square before transformation
Line N+2..2*N+1: N lines of N characters (each either `@' or `-'); this is the square after transformation

SAMPLE INPUT (file transform.in)

3
@-@
---
@@-
@-@
@--
--@

OUTPUT FORMAT

A single line containing the the number from 1 through 7 (described above) that categorizes the transformation required to change from the `before' representation to the `after' representation.

SAMPLE OUTPUT (file transform.out)

1
这道题,情况太多了,脑壳都写晕了。。。。。很恶心
View Code
  1 #include<iostream>
  2 #include<algorithm>
  3 #include<string.h>
  4 #include<cstdio>
  5 #include<cstdlib>
  6 #include<cstring>
  7 
  8 using namespace std;
  9 
 10 char a[11][11];
 11 char b[11][11];
 12 char s[11][11];
 13 int n;
 14 int ok=0;
 15 
 16 
 17 int work1()
 18 {
 19      for(int i=1;i<=n;i++)
 20      {
 21          for(int j=1;j<=n;j++)
 22          {
 23              b[j][n+1-i]=a[i][j];
 24          }
 25      }
 26      int wx=1;
 27      for(int i=1;i<=n;i++)
 28      {
 29          for(int j=1;j<=n;j++)
 30          {
 31             if(b[i][j]!=s[i][j])
 32             {
 33               wx=0;
 34               break;
 35             }
 36          }
 37      }
 38      if(wx==1)
 39      {
 40         cout<<1<<endl;
 41         ok=1;
 42      }
 43 }
 44 
 45 int work2()
 46 {
 47      char c[11][11];
 48      for(int i=1;i<=n;i++)
 49      {
 50          for(int j=1;j<=n;j++)
 51          {
 52              b[j][n+1-i]=a[i][j];
 53          }
 54      }
 55      for(int i=1;i<=n;i++)
 56      {
 57          for(int j=1;j<=n;j++)
 58          {
 59              c[j][n+1-i]=b[i][j];
 60          }
 61      }
 62      int wx=1;
 63      for(int i=1;i<=n;i++)
 64      {
 65          for(int j=1;j<=n;j++)
 66          {
 67             if(c[i][j]!=s[i][j])
 68             {
 69               wx=0;
 70               break;
 71             }
 72          }
 73      }
 74      if(wx==1)
 75      {
 76         cout<<2<<endl;
 77         ok=1;
 78      }
 79 }
 80 
 81 int work3()
 82 {
 83     for(int i=1;i<=n;i++)
 84     {
 85        for(int j=1;j<=n;j++)
 86        {
 87           b[n+1-j][i]=a[i][j];
 88        }
 89     }
 90      int wx=1;
 91      for(int i=1;i<=n;i++)
 92      {
 93          for(int j=1;j<=n;j++)
 94          {
 95             if(b[i][j]!=s[i][j])
 96             {
 97               wx=0;
 98               break;
 99             }
100          }
101      }
102      if(wx==1)
103      {
104         cout<<3<<endl;
105         ok=1;
106      }
107 }
108 
109 
110 int work4()
111 {
112     for(int i=1;i<=n;i++)
113     {
114        for(int j=1;j<=n;j++)
115        {
116           b[i][n+1-j]=a[i][j];
117        }
118     }
119      int wx=1;
120      for(int i=1;i<=n;i++)
121      {
122          for(int j=1;j<=n;j++)
123          {
124             if(b[i][j]!=s[i][j])
125             {
126               wx=0;
127               break;
128             }
129          }
130      }
131      if(wx==1)
132      {
133         cout<<4<<endl;
134         ok=1;
135      }
136 }
137 
138 
139 int work5()
140 {
141     for(int i=1;i<=n;i++)
142     {
143        for(int j=1;j<=n;j++)
144        {
145           b[i][n+1-j]=a[i][j];
146        }
147      }
148      char c[11][11];
149      for(int i=1;i<=n;i++)
150      {
151          for(int j=1;j<=n;j++)
152          {
153              c[j][n+1-i]=b[i][j];
154          }
155      }
156      int wx=1;
157      for(int i=1;i<=n;i++)
158      {
159          for(int j=1;j<=n;j++)
160          {
161             if(c[i][j]!=s[i][j])
162             {
163               wx=0;
164               break;
165             }
166          }
167      }
168      if(wx==1)
169      {
170         cout<<5<<endl;
171         ok=1;
172      }
173      char d[11][11];
174      for(int i=1;i<=n;i++)
175      {
176          for(int j=1;j<=n;j++)
177          {
178              d[j][n+1-i]=c[i][j];
179          }
180      }
181      wx=1;
182      for(int i=1;i<=n;i++)
183      {
184          for(int j=1;j<=n;j++)
185          {
186             if(d[i][j]!=s[i][j])
187             {
188               wx=0;
189               break;
190             }
191          }
192      }
193      if(wx==1)
194      {
195         cout<<5<<endl;
196         ok=1;
197      }
198      for(int i=1;i<=n;i++)
199      {
200        for(int j=1;j<=n;j++)
201        {
202           c[n+1-j][i]=b[i][j];
203        }
204      }
205      wx=1;
206      for(int i=1;i<=n;i++)
207      {
208          for(int j=1;j<=n;j++)
209          {
210             if(c[i][j]!=s[i][j])
211             {
212               wx=0;
213               break;
214             }
215          }
216      }
217      if(wx==1)
218      {
219         cout<<5<<endl;
220         ok=1;
221      }
222 }
223     
224 void work6()
225 {
226      int wx=1;
227      for(int i=1;i<=n;i++)
228      {
229          for(int j=1;j<=n;j++)
230          {
231             if(a[i][j]!=s[i][j])
232             {
233               wx=0;
234               break;
235             }
236          }
237      }
238      if(wx==1)
239      {
240         cout<<6<<endl;
241         ok=1;
242      }
243 } 
244 
245 int main()
246 {
247      freopen("transform.in","r",stdin);
248      freopen("transform.out","w",stdout);
249      cin>>n;
250      for(int i=1;i<=n;i++)
251      {
252         for(int j=1;j<=n;j++)
253         {
254            cin>>a[i][j];
255         }
256      }
257      for(int i=1;i<=n;i++)
258      {
259         for(int j=1;j<=n;j++)
260         {
261            cin>>s[i][j];
262         }
263      }
264      if(ok!=1)
265      work1();
266      if(ok!=1)
267      work2();
268      if(ok!=1)
269      work3();
270      if(ok!=1)
271      work4();
272      if(ok!=1)
273      work5();
274      if(ok!=1)
275      work6();
276      if(ok!=1)
277      cout<<7<<endl;
278      return 0;
279 }
280      
281      

 

posted @ 2012-07-14 15:01  kaisadadi  阅读(198)  评论(0编辑  收藏  举报