欢迎访问 生活随笔!

生活随笔

当前位置: 首页 > 编程资源 > 编程问答 >内容正文

编程问答

USACO SECTION 1.1.2 Transformations 爆搜

发布时间:2023/12/20 编程问答 57 豆豆
生活随笔 收集整理的这篇文章主要介绍了 USACO SECTION 1.1.2 Transformations 爆搜 小编觉得挺不错的,现在分享给大家,帮大家做个参考.

  题目链接: http://train.usaco.org/usacoprob2?a=f6bhTTJaVRy&S=transform

  题目大意: 给你一个初始矩阵和一个目的矩阵, 还有几种操作, 输出最小的操作号。

  解题思路: 有个坑就是不应该直接判等, 因为要输出最小的操作号, 有可能就是旋转一下也可以得到原图形那么输出的就不是6了, 然后就是怎么旋转这个矩形, 想了好久然后想错了.....不说了, 上代码吧。

  代码: 

/*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

  思考: 自己的抽象思维能力还是太弱, 自己的代码能力还是太弱, 所以说还要加强, 另外今天该找丁濛了。

转载于:https://www.cnblogs.com/FriskyPuppy/p/6950322.html

总结

以上是生活随笔为你收集整理的USACO SECTION 1.1.2 Transformations 爆搜的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得生活随笔网站内容还不错,欢迎将生活随笔推荐给好友。