博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
USACO题目——Transformations
阅读量:6902 次
发布时间:2019-06-27

本文共 3250 字,大约阅读时间需要 10 分钟。

Transformations

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.

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 from the `before' representation to the `after' representation.

SAMPLE OUTPUT (file transform.out)

1
我的解答,代码比较多,不够简洁。
/* ID:rongkan1 LANG: C++ PROG:transform */ #include 
#include
void rotate270(char **sour,int n,char **destin); void rotate180(char **sour,int n,char **destin); void rotate90(char **sour,int n,char **destin); void reflection(char **sour,int n, char **destin); int isequal(char **p1,char **p2,int n); int main() {
FILE *fin = fopen("transform.in","r"), *fout = fopen("transform.out","w"); int n; fscanf(fin,"%d",&n); char **tmp = new char*[n]; char** des=new char*[n]; //用来计算的 char** p1=new char*[n]; //存储读入的转换前矩阵 char** p2=new char*[n]; //存储读入的转换后矩阵, char *line = new char[n+1]; for(int i=0;i

下面是官方解答:

/*
We represent a board as a data structure containing the dimension and the contents. We pass around the data structure itself, not a reference to it, so that we can return new boards, and so on. This makes it easy to define reflect and rotate operations that return reflected and rotated boards. Once we have these, we just check to see what combination of transformations makes the old board into the new board.
*/ #include 
#include
#include
#include
#define MAXN 10 typedef struct Board Board; struct Board {
int n; char b[MAXN][MAXN]; }; /* rotate 90 degree clockwise: [r, c] -> [c, n+1 - r] */ Board rotate(Board b) {
Board nb; int r, c; nb = b; for(r=0; r
[r, n-1 -c] */ Board reflect(Board b) {
Board nb; int r, c; nb = b; for(r=0; r

我得代码和官方解答有很大差距啊

转载于:https://www.cnblogs.com/stonehat/archive/2011/10/05/2199635.html

你可能感兴趣的文章
《威胁建模:设计和交付更安全的软件》——第一部分 入 门 指 南
查看>>
JetBrains 为学生教师推出免费 Student License
查看>>
《Adobe InDesign CS6中文版经典教程》—第2课2.8节处理对象
查看>>
《数据结构与抽象:Java语言描述(原书第4版)》一JI2.2.1 延缓处理:throws子句...
查看>>
《计算复杂性:现代方法》——2.2 归约和NP完全性
查看>>
Mozilla 宣布关闭 Persona
查看>>
Ubuntu和FreeBSD即将合体:UbuntuBSD
查看>>
漏洞预警:GitLab 权限泄露漏洞
查看>>
攻击者开始利用 ImageMagick 漏洞攻击网站
查看>>
《Java多线程编程核心技术》——1.12节本章小结
查看>>
看,那人好像一个产品狗,对,这就是产品狗
查看>>
《Visual Basic 2012入门经典》----2.3 使用工具栏
查看>>
《Nmap渗透测试指南》—第10章10.7节Scans标签
查看>>
Machine Learning in Action -- AdaBoost
查看>>
无等待是不够的
查看>>
在 Apache Hive 中轻松生存的12个技巧
查看>>
《树莓派开发实战(第2版)》——2.11 在Mac上共享树莓派的屏幕
查看>>
Scala 泛型
查看>>
API时代,每个人都能拥有阿凡达,天了撸!
查看>>
《制造业中的机器人、自动化和系统集成》—— 3.6 装配自动化组件
查看>>