usaco 1.1 Trasformations

来源:互联网 发布:csmhuan实时数据 编辑:程序博客网 时间:2024/06/05 00:07
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, NLine 2..N+1:N lines of N characters (each either `@' or `-'); this is the square before transformationLine 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 /*  2 ID: jings_h1  3 PROG: transform  4 LANG: C++  5 */  6   7 #include<iostream>  8 #include<fstream>  9 #include<stdio.h> 10 #include<string.h> 11 using namespace std; 12 int main(){ 13    FILE *fin = fopen("transform.in","r");   14    FILE *fout = fopen("transform.out","w");   15     int n; 16         fscanf(fin,"%d",&n); 17         char a[15][15]; 18         char a1[15][15]; 19         char b[15][15][15]; 20         memset(a,0,sizeof(a)); 21         memset(b,0,sizeof(b)); 22         for(int i=0;i<n;i++){ 23              fscanf(fin,"%s",a[i]); 24              //scanf("%s",a[i]); 25              } 26         for(int i=0;i<n;i++){ 27              fscanf(fin,"%s",a1[i]); 28              //scanf("%s",a1[i]); 29              } 30         for(int i=n-1;i>=0;i--){ 31                 for(int j=0;j<n;j++){ 32                         b[1][j][i]=a[n-1-i][j]; 33                         } 34                 } 35         for(int i=0;i<n;i++){ 36                 for(int j=0;j<n;j++){ 37                         b[3][j][i]=a[i][n-1-j]; 38                         } 39                         } 40         for(int i=0;i<n;i++){ 41                 for(int j=0;j<n;j++){ 42                         b[2][i][j]=a[n-1-i][n-1-j]; 43                         } 44                         } 45         for(int i=0;i<n;i++){ 46                 for(int j=0;j<n;j++){ 47                         b[4][i][j]=a[i][n-1-j]; 48                         } 49                         } 50         for(int i=0;i<n;i++){ 51                 for(int j=0;j<n;j++){ 52                         b[5][j][i]=b[4][i][n-1-j]; 53                         } 54                         } 55         for(int i=n-1;i>=0;i--){ 56                 for(int j=0;j<n;j++){ 57                         b[0][j][i]=b[4][n-1-i][j]; 58                         } 59                         } 60          for(int i=0;i<n;i++){ 61                 for(int j=0;j<n;j++){ 62                         b[7][i][j]=b[4][n-1-i][n-1-j]; 63                         } 64                         } 65     /*    for(int i=0;i<6;i++){ 66                 cout<<i<<endl; 67                 for(int j=0;j<n;j++){ 68                         printf("%s\n",b[i][j]); 69                         } 70                 cout<<endl; 71                 }*/ 72          73         int k; 74         for(k=1;k<=5;k++){ 75                 int j; 76                 for(j=0;j<n;j++){ 77                 if(strcmp(a1[j],b[k][j])!=0){  78                        break; 79                        } 80                        } 81                 if(j>=n){ 82                 fprintf(fout,"%d\n",k);   83                // cout<<k<<endl; 84                 break; 85                 } 86                        } 87         if(k<=5){ 88              return 0; 89              } 90        int i;   91         for(i=0;i<n;i++){ 92             if(strcmp(a1[i],b[0][i])!=0){ 93                    break; 94                    } 95               } 96         if(i>=n){ 97               fprintf(fout,"5\n");   98         //cout<<"5"<<endl; 99               //continue;100               return 0;101               }102         for(i=0;i<n;i++){103             if(strcmp(a1[i],b[7][i])!=0){104                    break;105                    }106               }107         if(i>=n){108               fprintf(fout,"5\n");  109         //cout<<"5"<<endl;110               //continue;111               return 0;112               }113         for( i=0;i<n;i++){114             if(strcmp(a1[i],a[i])!=0){115               break;116               }117               }118         if(i>=n){119             fprintf(fout,"6\n");  120            // cout<<"6"<<endl;121            // continue;122            return 0;123             }124         if(k>5){125                 fprintf(fout,"7\n");  126               //  cout<<"7"<<endl;127                 }128         return 0;129         }130