USACO SECTION 1.1.2 Transformations 爆搜
生活随笔
收集整理的這篇文章主要介紹了
USACO SECTION 1.1.2 Transformations 爆搜
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
題目鏈接:?http://train.usaco.org/usacoprob2?a=f6bhTTJaVRy&S=transform
題目大意: 給你一個初始矩陣和一個目的矩陣, 還有幾種操作, 輸出最小的操作號。
解題思路: 有個坑就是不應(yīng)該直接判等, 因為要輸出最小的操作號, 有可能就是旋轉(zhuǎn)一下也可以得到原圖形那么輸出的就不是6了, 然后就是怎么旋轉(zhuǎn)這個矩形, 想了好久然后想錯了.....不說了, 上代碼吧。
代碼:?
/*ID: wl199701PROG: transformLANG: 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; } View Code思考: 自己的抽象思維能力還是太弱, 自己的代碼能力還是太弱, 所以說還要加強, 另外今天該找丁濛了。
轉(zhuǎn)載于:https://www.cnblogs.com/FriskyPuppy/p/6950322.html
總結(jié)
以上是生活随笔為你收集整理的USACO SECTION 1.1.2 Transformations 爆搜的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 10 个最佳的 Node.js 的 MV
- 下一篇: c#简单自定义异常处理日志辅助类