rotate:
for(int i = 0; i<n; ++i)
for(int j=0; j<n; ++j)
a[j][n-i-1] = b[i][j];
reflect:
for(int i = 0; i<n; ++i)
for(int j =0; j<n; ++j)
a[i][n-j-1] = b[i][j];
/**//*
ID: lorelei3
PROG: transform
LANG: C++
*/
#include <fstream>
#include <iostream>
using namespace std;
const int MAX = 15;
typedef struct Board{
int m_nSize;
char m_cBoard[MAX][MAX];
} Board, *pBoard;
Board rotate(Board b) {
Board nb = b;
for(int i=0; i<b.m_nSize; ++i)
for(int j=0; j<b.m_nSize; ++j)
nb.m_cBoard[j][b.m_nSize-1-i]=b.m_cBoard[i][j];
return nb;
}
Board reflect(Board b){
Board nb = b;
for(int i=0; i <b.m_nSize; ++i)
for(int j=0; j<b.m_nSize; ++j)
nb.m_cBoard[i][b.m_nSize-1-j] = b.m_cBoard[i][j];
return nb;
}
int eqBoard(Board a, Board b){
int size = 0;
if(a.m_nSize!=b.m_nSize)
return 0;
size = a.m_nSize;
for(int i=0; i<size; ++i)
for(int j=0; j<size; ++j)
if(a.m_cBoard[i][j]!=b.m_cBoard[i][j])
return 0;
return 1;
}
int main(){
int i,j,n;
int ans=0;
Board a,b;
ifstream in("transform.in");
ofstream out("transform.out");
in>>n;
a.m_nSize = n;
b.m_nSize = n;
for(i=0; i<n; ++i)
for(j=0; j<n; ++j)
in>>a.m_cBoard[i][j];
for(i=0; i<n; ++i)
for(j=0; j<n; ++j)
in>>b.m_cBoard[i][j];
if(eqBoard(b, rotate(a)))
ans = 1;
else if(eqBoard(b, rotate(rotate(a))))
ans = 2;
else if(eqBoard(b, rotate(rotate(rotate(a)))))
ans = 3;
else if(eqBoard(b, reflect(a)))
ans = 4;
else if(eqBoard(b, rotate(reflect(a)))
|| eqBoard(b, rotate(rotate(reflect(a))))
|| eqBoard(b, rotate(rotate(rotate(reflect(a))))))
ans = 5;
else if(eqBoard(b,a))
ans = 6;
else
ans = 7;
out<<ans<<endl;
return 0;
}
posted on 2010-11-09 00:44
小阮 阅读(163)
评论(0) 编辑 收藏 引用 所属分类:
USACO