Transformations
A square pattern of size N x N (1 <= N <=) Black and white square tiles are transformed into another square patter N. Write a program that would recognize the minimum transformation that have been applied to the original pattern given the Following list of possible transformations:
- #1: Degree rotation:the pattern was rotated clockwise degrees.
- #2: Rotation:the pattern was rotated clockwise degree degrees.
- #3: Degree rotation:the pattern was rotated clockwise degrees.
- #4: Reflection:the pattern was reflected horizontally (turned to a mirror image of itself by reflecting around a vertic Al line in the middle of the image).
- #5: Combination:the pattern is reflected horizontally and then subjected to one of the rotations (#1-#3).
- #6: No change:the original pattern is not changed.
- #7: Invalid transformation:the New pattern was wasn't obtained by any of the above methods.
In the than one transform could has been used, choose the one with the minimum number above.
Program Name:transforminput 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 '-'); The square after transformation |
SAMPLE INPUT (file transform.in)
3@[email protected]---@@-@[email protected]@--[email protected]
OUTPUT FORMAT
A single line containing the number from 1 through 7 (described above) that categorizes the transformation required to Change in the ' before ' representation to the ' after ' representation.
SAMPLE OUTPUT (file transform.out)
1
Encountered a small problem, that is, local and Usaco results are not the same, the original is a few words return.
/*user:rao wenjintask:transformlang:c++*/#include <iostream> #include <cstdio> #include <cstring># Define N 15using namespace Std;char s[2][n][n];int n,op;void rot (char s[][n],int times) {char t[n][n]; memset (T,0,sizeof t); for (int i=1;i<=times;i++) {for (Int. i=0;i<n;i++) for (int j=0;j<n;j++) t[j][n-i-1]=s[i][j];memcpy (S,t,sizeof t ); }}void Refl (char S[][n]) {for (Int. i=0;i<n;i++) for (int j=0;j<n/2;j++) swap (S[i][n-j-1],s[i][j]) ;} int ck () {for (Int. i=0;i<n;i++) for (int j=0;j<n;j++) if (S[1][i][j]!=s[0][i][j]) return 0; return 1;} int work (int op) {if (op==1) rot (s[0],1); if (op==2) rot (s[0],1); if (op==3) rot (s[0],1); if (op==4) Rot (s[0],1), REFL (S[0]); if (op==5) {for (int i=0;i<3;i++) {rot (s[0],1); if (CK ()) return 1; } return 0;//This sentence misses}else return ck ();} int main () {freopen ("transform.in", "R", stdin); Freopen ("Transform.out", "w", stdout); cin>>n; for (int k=0;k<2;k++) for (int i=0;i<n;i++) cin>>s[k][i]; for (op=1;op<7;op++) if (Work (OP)) {Cout<<op<<endl;break;} if (op==7) Cout<<7<<endl;}
"Usaco" Transformations (analog)