USACO 1.2 Problem 2
来源:互联网 发布:动漫创作软件 编辑:程序博客网 时间:2024/06/12 01:27
代码丑的不能直视系列,其实可以用循环把代码整的好看一些,不过没有这个必要了。
题目描述:
输入一组图案,再输入一组图案,给你几个操作,让你判断是否能通过这些操作把第一幅图案转换到第二幅。那么这道题是基础题,因为只需要按顺序来一遍就好了。
算法思想:
也就是训练了一下写旋转数组和对称数组的技巧,其他就没有什么值得说的了。就是各种循环,看code的话应该直接就可以看懂。
关于rotate和reflect,其实用纸写下来就可以完成变换。
代码部分:
#include <fstream>#include <iostream>#include <map>using namespace std;ifstream fin("transform.in");ofstream fout("transform.out");int n;char c[12][12];char tmp[12][12];char res[12][12];bool match(char c1[12][12],char c2[12][12]) {for (int i = 1; i <= n; ++i) {for (int j = 1; j <= n; ++j) {if (c1[i][j] != c2[i][j]) return false;}}return true;}void rotate(char c1[12][12]) {for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {tmp[j][n+1-i] = c1[i][j];}}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {c1[i][j] = tmp[i][j];}}}void reflect(char c1[12][12]) {for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {tmp[i][n+1-j] = c1[i][j];}}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {c1[i][j] = tmp[i][j];}}}int main() {fin >> n;for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {fin >> c[i][j];}}for (int i = 1; i <= n; i++) {for (int j = 1; j <= n; j++) {fin >> res[i][j];}}rotate(c);if (match(c, res)) {fout << "1" << endl;return 0;}rotate(c);if (match(c, res)) {fout << "2" << endl;return 0;}rotate(c);if (match(c, res)) {fout << "3" << endl;return 0;}rotate(c);reflect(c);if (match(c, res)) {fout << "4" << endl;return 0;}rotate(c);if (match(c, res)) {fout << "5" << endl;return 0;}rotate(c);if (match(c, res)) {fout << "5" << endl;return 0;}rotate(c);if (match(c, res)) {fout << "5" << endl;return 0;}rotate(c);if (match(c, res)) {fout << "6" << endl;return 0;}fout << "7" << endl;return 0;}
0 0
- USACO 1.2 Problem 2
- USACO 1.2 Problem 1
- USACO 1.1 Problem 2
- USACO 1.2 Problem 4 Palindromic Square
- USACO 1.2 Problem 5 Dual palindromic
- USACO 1.2 Problem 3 Name That Number
- USACO 1.1 Problem 1
- USACO 1.1 Problem 3
- USACO 1.1 Problem 4
- 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
- USACO 1.2.2 Transformations
- usaco 1.2.2 transform
- usaco 1.2.2
- USACO 1.2.2 Transformations(transform)
- Linux man命令的使用方法
- Codeforces Round #181 (Div. 2)---C. Beautiful Numbers
- 推荐几个hadoop搭建的几个好的博文,亲测成功!
- poj1741 Tree
- C++ primer第4章
- USACO 1.2 Problem 2
- 取10个随机数, 每个数的取值范围是20-25, 找出其中重复的数, 重复次数
- VBP/VFP/HBP/HFP
- 如何将你的设计理念付诸实践
- 转义字符和格式字符
- 复习
- UVa 10935 - Throwing cards away I
- 写作是一种爱好
- 模拟shell进程