USACO-Section1.2 Transformations [其他]
来源:互联网 发布:linux下socket编程 编辑:程序博客网 时间:2024/05/22 23:57
2017-6-1
题目大意
一块N x N(1<=N<=10)正方形的黑白瓦片的图案要被转换成新的正方形图案。写一个程序来找出将原始图案按照以下列转换方法转换成新图案的最小方式:
1:转90度:图案按顺时针转90度。
2:转180度:图案按顺时针转180度。
3:转270度:图案按顺时针转270度。
4:反射:图案在水平方向翻转(以中央铅垂线为中心形成原图案的镜像)。
5:组合:图案在水平方向翻转,然后再按照1到3之间的一种再次转换。
6:不改变:原图案不改变。
7:无效转换:无法用以上方法得到新图案。
如果有多种可用的转换方法,请选择序号最小的那个。
只使用1~7中的一个步骤来完成这次转换。
(copy from nocow)
题解
实现上面提到的几种变换,依次尝试即可。
代码
/*ID: zachery1PROG: transformLANG: C++*/#include <iostream>#include <fstream>#define MAXN 20#define cin fin#define cout foutusing namespace std;ifstream fin("transform.in");ofstream fout("transform.out");char a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN][MAXN];char tmp[MAXN][MAXN];int N;inline bool isSame() { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) if (tmp[i][j] != b[i][j]) return false; return true;}bool fun1(char a[][MAXN]) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) tmp[j][N-1-i] = a[i][j]; return isSame();}bool fun2(char a[][MAXN]) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) tmp[N-1-i][N-1-j] = a[i][j]; return isSame();}bool fun3(char a[][MAXN]) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) tmp[N-1-j][i] = a[i][j]; return isSame();}bool fun4(char a[][MAXN], char tmp[][MAXN]) { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) tmp[i][N-1-j] = a[i][j]; return isSame();}bool fun5() { fun4(a, c); if (fun1(c) || fun2(c) || fun3(c)) return true; else return false;}bool fun6() { for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) tmp[i][j] = a[i][j]; return isSame();}void solve() { int ans; if (fun1(a)) ans = 1; else if (fun2(a)) ans = 2; else if (fun3(a)) ans = 3; else if (fun4(a, tmp)) ans = 4; else if (fun5()) ans = 5; else if (fun6()) ans = 6; else ans = 7; cout << ans << endl;}int main() { ios::sync_with_stdio(false); cin >> N; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> a[i][j]; for (int i = 0; i < N; i++) for (int j = 0; j < N; j++) cin >> b[i][j]; solve (); return 0;}
阅读全文
0 0
- USACO-Section1.2 Transformations [其他]
- USACO 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 Transformations
- USCAO-Section1.2 Transformations
- USACO-Section1.2 Milking Cows [其他]
- USACO-Section1.2 Name That Number [其他]
- USACO之Section1.2.2 Transformations[模拟]
- USACO-Section1.3Wormholes[其他]
- USACO 1.2.2 Transformations
- [USACO 1.2.2] Transformations
- USACO 1.2.2 Transformations
- USACO 1.2.2 Transformations
- USACO 1.2.2 Transformations
- Struts2配置图解
- Problem D: STL——括号匹配
- java内存同步模型
- 查询进程打开的文件(转)
- ubuntu 16.04安装使用leap motion
- USACO-Section1.2 Transformations [其他]
- Shiro拦截AJAX的解决方案
- Eclipse常用快捷键
- 用css绘制各种形状(放松一下)
- 了解systemServer
- 浅谈display:flex
- java中Unicode码与中文的转化
- 使用 cURL 进行 HTTP 请求实例
- 二叉树