USCAO-Section1.2 Transformations
来源:互联网 发布:重庆seo俱乐部 编辑:程序博客网 时间:2024/05/16 05:27
原题:
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:
1: 90 Degree Rotation: The pattern was rotated clockwise 90 degrees.
2: 180 Degree Rotation: The pattern was rotated clockwise 180 degrees.
3: 270 Degree Rotation: The pattern was rotated clockwise 270 degrees.
4: Reflection: The pattern was reflected horizontally (turned into a mirror image of itself by reflecting around a vertical line in the middle of the image).
5: Combination: The pattern was reflected horizontally and then subjected to one of the rotations (#1-#3).
6: No Change: The original pattern was not changed.
7: Invalid Transformation: The new pattern was not obtained by any of the above methods.
In the case that more than one transform could have been used, choose the one with the minimum number above.
题意:给定两个n*n(1<=n<=10)的矩阵,通过1-7的操作是否能使两个矩阵相同,输出序号小的操作。
1、顺时针旋转90度
2、顺时针旋转180度
3、顺时针旋转270度
4、轴对称
5、轴对称后进行一次1-3的操作
6、不做操作
7、无法通过上面的操作得到
题解:
说是有七个操作,其实只有旋转九十度和轴对称两个操作,180和270分别是两次和三次操作1.
代码:
/*ID:newyear111PROG: transformLANG: C++*/#include <iostream>#include <fstream>#include <string>#include<algorithm>using namespace std;const int N=15;char a[N][N];char b[N][N];int n; //判定两个矩阵是否相等 bool isOK(){ for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ if(a[i][j]!=b[i][j]) return false; } } return true;}//旋转90°的操作 void f1(){ int t[N][N]; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ t[i][j]=a[n-j-1][i]; } } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ a[i][j]=t[i][j]; } }// for(int i=0;i<n;i++){// for(int j=0;j<n;j++){// cout<<a[i][j]<<" ";// }// cout<<endl;// } }//轴对称操作 void f2(){ for(int i=0;i<n;i++){ for(int j=0;j<n/2;j++) { swap(a[i][j],a[i][n-j-1]); } }// for(int i=0;i<n;i++){// for(int j=0;j<n;j++){// cout<<a[i][j]<<" ";// }// cout<<endl;// } } int main(){ ifstream fin("transform.in"); ofstream fout("transform.out"); fin>>n; for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ fin>>a[i][j]; } }// for(int i=0;i<n;i++){// for(int j=0;j<n;j++){// fout<<a[i][j]<<" ";// }// fout<<endl;// } for(int i=0;i<n;i++){ for(int j=0;j<n;j++){ fin>>b[i][j]; } }// for(int i=0;i<n;i++){// for(int j=0;j<n;j++){// fout<<b[i][j]<<" ";// }// fout<<endl;// } //判定是否原矩阵就相等 bool flag=false; if(isOK()){ flag=true; } //判定操作1-3是否可以完成要求 for(int i=0;i<3;i++){ f1(); if(isOK()){ fout<<i+1<<endl; return 0; } } //转360°还原矩阵 f1(); //进行操作4 f2(); if(isOK()){ fout<<4<<endl; return 0; } //在操作四的基础上看是否满足5的要求 for(int i=0;i<3;i++){ f1(); if(isOK()){ fout<<5<<endl; return 0; } } //根据先前的判断看是否不操作就相等 if(flag){ fout<<6<<endl; return 0; } //无法得到相等的矩阵 fout<<7<<endl; fin.close(); fout.close(); return 0;}
- USCAO-Section1.2 Transformations
- USCAO-Section1.2 Transformations
- USACO Section1.2 Transformations
- USACO-Section1.2 Transformations
- usaco section1.2 Transformations
- USACO Section1.2 Transformations
- USACO-Section1.2 Transformations
- USCAO section1.2 Palindromic Squares
- USCAO-Section1.2 Milking Cows
- USACO-Section1.2 Transformations [其他]
- USACO-Section1.2 Transformations【数论.矩阵旋转】
- USCAO section 1.1 Transformations
- USCAO section1.3 Barn Repair
- USCAO-Section1.1 Your Ride Is Here
- USCAO-Section1.1 Greedy Gift Givers
- USCAO-Section1.1 Friday the Thirteenth
- USCAO-Section1.1 Broken Necklace(DP版)
- USACO之Section1.2.2 Transformations[模拟]
- jedis基本操作
- Ubuntu aria2c 下载
- 算法导论——二叉查找树
- osg矩阵
- mysql sql语句查询字符串对比
- USCAO-Section1.2 Transformations
- 常考算法与数据结构--面试准备
- in 和 exist 区别
- 交换排序算法:冒泡排序-Bubble Sort
- Unity3D的单例框架以及单例框架的使用
- 寄居蟹与海葵
- Android实现搜索附近WiFi并显示在视图中
- android studio中?attr报错的问题
- spring cloud组件大概介绍