标签:
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:
In the case that more than one transform could have been used, choose the one with the minimum number above.
| 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 |
3 @-@ --- @@- @-@ @-- --@
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.
1
遇到了小问题,就是本地和USACO结果不一样,原来是少了句return。
/*
USER: RAO WENJIN
TASK: transform
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 15
using 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;//这句漏了
}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;
}
标签:
原文地址:http://www.cnblogs.com/flipped/p/5847748.html