usaco1.2.2 transform
題目:
TransformationsA 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題目其實(shí)很簡(jiǎn)單,第一遍看題時(shí)想復(fù)雜了( 我想的是經(jīng)過一系列變化,而題目要求只是其中某一次變化,后來仔細(xì)看輸出只要一個(gè)數(shù)字,才改正確 )
題意是說有七種變化方式,1,順指針90度,2,180度,3,270度,4,鏡面,5,鏡面后按1--3轉(zhuǎn),6,不變,7,1--6都搞不定。最初用函數(shù)寫,方式到很簡(jiǎn)單,不知道為何在引用函數(shù)式出問題了,一氣之下就全部刪掉,然后全部弄到main里面。結(jié)果初始化flag時(shí)又有點(diǎn)想當(dāng)然,認(rèn)為會(huì)自動(dòng)為1,結(jié)果又錯(cuò)了幾次。
代碼: /* 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; }
轉(zhuǎn)載于:https://www.cnblogs.com/rolyxiao/archive/2012/06/02/2531953.html
總結(jié)
以上是生活随笔為你收集整理的usaco1.2.2 transform的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Android210更新2---支持喇叭
- 下一篇: (转)C#2.0泛型--Dictiona