本文主要是介绍usaco 1.2 Transformations(模拟),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
我的做法就是一个一个情况枚举出来
注意计算公式:
( 变换后的矩阵记为C)
顺时针旋转90°:C[i] [j]=A[n-j-1] [i]
(旋转180°和270° 可以多转几个九十度来推)
对称:C[i] [n-j-1]=A[i] [j]
代码有点长 。。。
/*
ID: who jay
LANG: C++
TASK: transform
*/
#include<stdio.h>bool cmp(char B[][10],char C[][10],int n)
{int i,j;bool flag=1;for(i=0; i<n; i++){if(!flag)break;for(j=0; j<n; j++)if(B[i][j]!=C[i][j]){return 0;flag=0;break;}}if(flag)return 1;
}void rotate(char A[][10],char C[][10],int n)
{int i,j;for(i=0; i<n; i++)for(j=0; j<n; j++)C[i][j]=A[n-j-1][i];
}void reflect(char A[][10],char C[][10],int n)
{int i,j;for(i=0; i<n ; i++)for(j=0; j<n; j++)C[i][n-j-1]=A[i][j];
}int main()
{FILE *fin = fopen ("transform.in", "r");FILE *fout = fopen ("transform.out", "w");int n,i,j;bool flag;char A[10][10],B[10][10],C[10][10],D[10][10];fscanf(fin,"%d",&n);flag=1;for(i=0; i<n; i++)fscanf(fin,"%s",A[i]);for(i=0; i<n; i++)fscanf(fin,"%s",B[i]);rotate(A,C,n);if(flag && cmp(B,C,n)){fprintf(fout,"1\n");flag=0;}rotate(C,D,n);if(flag && cmp(B,D,n)){fprintf(fout,"2\n");flag=0;}rotate(D,C,n);if(flag && cmp(B,C,n)){fprintf(fout,"3\n");flag=0;}reflect(A,C,n);if(flag && cmp(B,C,n)){fprintf(fout,"4\n");flag=0;}rotate(C,D,n);if(flag && cmp(B,D,n)){fprintf(fout,"5\n");flag=0;}rotate(D,C,n);if(flag && cmp(B,C,n)){fprintf(fout,"5\n");flag=0;}rotate(C,D,n);if(flag && cmp(B,D,n)){fprintf(fout,"5\n");flag=0;}if(flag && cmp(A,B,n)){fprintf(fout,"6\n");flag=0;}if(flag)fprintf(fout,"7\n");return 0;
}
这篇关于usaco 1.2 Transformations(模拟)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!