第二层第二题:矩阵变换
来源:互联网 发布:得无异乎的互 编辑:程序博客网 时间:2024/06/14 18:55
Transformations
A square pattern of size N x N (1 <= N <= 10) black and white squaretiles is transformed into another square pattern. Write a program that willrecognize the minimum transformation that has been applied to the originalpattern 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 theone with the minimum number above.
PROGRAM NAME: transform
INPUT FORMAT
Line 1:
A single integer, N
Line 2..N+1:
N lines of N characters (each either `@' or `-'); this is the square before transformation
Line N+2..2*N+1:
N lines of N characters (each either `@' or `-'); this is the square after transformation
SAMPLE INPUT (file transform.in)
3
@-@
---
@@-
@-@
@--
--@
OUTPUT FORMAT
A single line containing the the number from 1 through 7(described above) that categorizes the transformation required to change fromthe `before' representation to the `after' representation.
SAMPLE OUTPUT (file transform.out)
1
题目大意是给出两个N*N的由’@’和’_’构成的矩阵,第一个为初始矩阵,第二个为目标矩阵,矩阵可以支持如下七种操作:
1、顺时针转90度。
2、顺时针转180度。
3、顺时针转270度。= =!
4、关于水平方向上的中心线对称
例如:
执行4操作后:
5、先执行4操作,再执行1、2、3操作的任意一种。
6、不用操作就可以到达目标状态。(←_←)
7、怎么操作都到达不了目标状态。(↑_↑)
描述完成,那么问题来了:要怎么变换才能达到目标状态?请输出变换步骤。
初次一看这题吓了一跳。。。这尼玛不是八数码一类的题目?机智的楼主又一次开了百度。。。发现一片人都说这题是只要一步变换就可以了。于是将信将疑地去试了一下。。。还真的过了,好吧。。。那么这只是一道模拟题,注意一下各方块变换前和变换后的坐标关系,就可以for循环解决了(≥W≤)
附上代码:
/*ID:su1q2d21LANG:C++TASK:transform*/#include<iostream>#include<cstdio>#define maxn 20using namespace std;int n;char tmp[maxn][maxn],tmp1[maxn][maxn];char st[maxn][maxn],ed[maxn][maxn];bool chk(char tmp[][maxn]){int i,j;for(i=1;i<=n;i++){for(j=1;j<=n;j++){if(tmp[i][j]!=ed[i][j]) return false;}}return true;}void opt(int x,char st[][maxn],char tmp[][maxn]){int i,j;if(x==1){for(i=1;i<=n;i++){for(j=1;j<=n;j++) tmp[j][n-i+1]=st[i][j];}}if(x==2){for(i=1;i<=n;i++){for(j=1;j<=n;j++) tmp[n-i+1][n-j+1]=st[i][j];}}if(x==3){for(i=1;i<=n;i++){for(j=1;j<=n;j++) tmp[n-j+1][i]=st[i][j];}}if(x==4){for(i=1;i<=n;i++){for(j=1;j<=n;j++) tmp[i][n-j+1]=st[i][j];}}return ;}int main(){freopen("transform.in","r",stdin);freopen("transform.out","w",stdout);int i,j;char ctmp;scanf("%d",&n);for(i=1;i<=n;i++){for(j=1;j<=n;j++){scanf("%c",&ctmp);while(ctmp!='@' && ctmp!='-') scanf("%c",&ctmp);st[i][j]=ctmp;}}for(i=1;i<=n;i++){for(j=1;j<=n;j++){scanf("%c",&ctmp);while(ctmp!='@' && ctmp!='-') scanf("%c",&ctmp);ed[i][j]=ctmp;}}opt(1,st,tmp);if(chk(tmp)){printf("1\n");return 0;}opt(2,st,tmp);if(chk(tmp)){printf("2\n");return 0;}opt(3,st,tmp);if(chk(tmp)){printf("3\n");return 0;}opt(4,st,tmp);if(chk(tmp)){printf("4\n");return 0;}opt(1,tmp,tmp1);if(chk(tmp1)){printf("5\n");return 0;}opt(2,tmp,tmp1);if(chk(tmp1)){printf("5\n");return 0;}opt(3,tmp,tmp1);if(chk(tmp1)){printf("5\n");return 0;}if(chk(st)){printf("6\n");return 0;}printf("7\n");return 0;}
- 第二层第二题:矩阵变换
- 第二层
- 第二层第一题:挤牛奶
- 第二层第三题:名字和数字
- 第二层第四题:回文平方数
- 为了第二层 前进
- 第二章、应用层
- 第二层---策略模式
- 第二层内容:枚举
- Manager第二层
- dp专题 第二题 最大子矩阵
- 矩阵第二节
- 向着第二层 第一阶段第二天
- 向着第二层 第一阶段第二十一天
- 向着第二层 第一阶段第二十四天
- 第二章第二题
- 第二章第二题
- 第二章第二题
- QT5 学习之路23---事件总结
- UVa 1225 - Digit Counting【打表】
- LinkedList 增删真的比ArrayList快吗?
- 重载(overload),覆盖(override),隐藏(hide)的区别
- <一> 导言
- 第二层第二题:矩阵变换
- 播放与暂停UIWebView中视频,并获取的长度与播放进度,
- Android适配器Adapter学习
- 简单0-1背包
- UITableView的优化问题
- UVA 11991 Easy Problem from Rujia Liu?
- 文本分类入门(一)文本分类问题的定义
- 冒烟测试
- 设计模式之访问者模式