usaco1.2.2 transform
题目:
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
题目其实很简单,第一遍看题时想复杂了( 我想的是经过一系列变化,而题目要求只是其中某一次变化,后来仔细看输出只要一个数字,才改正确 )
题意是说有七种变化方式,1,顺指针90度,2,180度,3,270度,4,镜面,5,镜面后按1--3转,6,不变,7,1--6都搞不定。最初用函数写,方式到很简单,不知道为何在引用函数式出问题了,一气之下就全部删掉,然后全部弄到main里面。结果初始化flag时又有点想当然,认为会自动为1,结果又错了几次。
代码:
/* ID:614433244 PROG: transform LANG: C++ */ #include"iostream" #include"cstdio" #include"cstring" using namespace std; char a[11][11],b[11][11],c[11][11]; int n; int main() { freopen("transform.in","r",stdin); freopen("transform.out","w",stdout); cin>>n; int i,j; for( i=1;i<=n;i++ ) for( j=1;j<=n;j++ ) { cin>>a[i][j]; c[i][n+1-j]=a[i][j]; } for( i=1;i<=n;i++ ) for( j=1;j<=n;j++ ) cin>>b[i][j]; int temp=7; bool flag; if( temp==7 )//90度 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( a[i][j]!=b[j][n+1-i] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=1; } if( temp==7 )//180度 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( a[i][j]!=b[n+1-i][n+1-j] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=2; } if( temp==7 )//270度 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( a[i][j]!=b[n+1-j][i] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=3; } if( temp==7 )//镜面 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( c[i][j]!=b[i][j] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=4; } // if( temp==7 )//第五种 // { if( temp==7 )//90度 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( c[i][j]!=b[j][n+1-i] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=5; } if( temp==7 )//180度 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( c[i][j]!=b[n+1-i][n+1-j] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=5; } if( temp==7 )//270度 { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( c[i][j]!=b[n+1-j][i] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=5; } // } if( temp==7 ) { flag=1; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) if( a[i][j]!=b[i][j] ) { flag=0;break; } if( !flag ) break; } if( flag ) temp=6; } /* for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) cout<<a[i][j]; cout<<endl; } cout<<endl; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) cout<<c[i][j]; cout<<endl; } cout<<endl; for( i=1;i<=n;i++ ) { for( j=1;j<=n;j++ ) cout<<b[i][j]; cout<<endl; } cout<<endl; */ printf("%d\n",temp); return 0; }