题目链接: http://train.usaco.org/usacoprob2?a=f6bhTTJaVRy&S=transform
题目大意: 给你一个初始矩阵和一个目的矩阵, 还有几种操作, 输出最小的操作号。
解题思路: 有个坑就是不应该直接判等, 因为要输出最小的操作号, 有可能就是旋转一下也可以得到原图形那么输出的就不是6了, 然后就是怎么旋转这个矩形, 想了好久然后想错了.....不说了, 上代码吧。
代码:
/* ID: wl199701 PROG: transform LANG: C++ */ #include <iostream> #include <cstring> #include <cstdio> #include <string> #include <fstream> #include <iterator> #include <map> #include <algorithm> using namespace std; int n; const int maxn = 15; struct node { char a[maxn][maxn]; node() { memset(a, 0, sizeof(a)); } }; node st, des; node rnode() { node temp; for( int i = 1; i <= n; i++ ) { for( int j = 1; j <= n; j++ ) { cin >> temp.a[i][j]; } } return temp; } int ok( node n1, node n2 ) { for( int i = 1; i <= n; i++ ) { for( int j = 1; j <= n; j++ ) { if( n1.a[i][j] != n2.a[i][j] ) return 0; } } return 1; } void debug( node nd ) { for( int i = 1; i <= n; i++) { for( int j = 1; j <= n; j++ ) { cout << nd.a[i][j]; } cout << endl; } } node change(node ori, int op) { node temp; for( int i = 1; i <= n; i++ ) { for( int j = 1; j <= n; j++ ) { switch (op) { case 1: temp.a[i][j] = ori.a[n-j+1][i]; break; case 2: temp.a[i][j] = ori.a[n+1-i][n+1-j]; break; case 3: temp.a[i][j] = ori.a[j][n-i+1]; break; case 4: temp.a[i][j] = ori.a[i][n+1-j]; break; } } } return temp; } int main(){ freopen("transform.in","r",stdin); freopen("transform.out","w",stdout); while( scanf( "%d", &n ) == 1 ) { node a, b; a = rnode(); b = rnode(); // node temp = change(a, 1); // debug(temp); int flag = 0; int i; for( i = 1; i <= 4; i++ ) { node temp; temp = change(a, i); if( ok( temp, b ) ) { flag = 1; cout << i << endl; break; } } if( !flag ) { node temp = change( a, 4 ); for( int j = 1; j <= 3; j++ ) { node temp1 = change(temp, j); if( ok( temp1, b ) ) { flag = 1; cout << "5" << endl; break; } } } if( !flag ) { if( ok( a, b ) ) { cout << "6" << endl; continue; } } if( !flag ) { cout << "7" << endl; } } return 0; }
思考: 自己的抽象思维能力还是太弱, 自己的代码能力还是太弱, 所以说还要加强, 另外今天该找丁濛了。