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

一A的题,好happy。
不难,就是很麻烦。我是把前四个操作写成四个函数。其中旋转90度作为基本的函数,旋转180和旋转270都是由两次和三次旋转90度得到。
主要的问题就是int**和int a[][11]这两种传递参数时候遇到的麻烦,不知道怎么把两者统一起来,所以每次都要先把int**复制到一个数组里面,再作为参数传递给下一个函数,下午去找找资料吧。
 /*ID:Moment1991
PROG:transform
LANG:C++
Compiling...
Compile: OK Executing...
Test 1: TEST OK [0.000 secs, 3496 KB]
Test 2: TEST OK [0.003 secs, 3496 KB]
Test 3: TEST OK [0.008 secs, 3496 KB]
Test 4: TEST OK [0.008 secs, 3496 KB]
Test 5: TEST OK [0.005 secs, 3496 KB]
Test 6: TEST OK [0.003 secs, 3496 KB]
Test 7: TEST OK [0.005 secs, 3496 KB]
Test 8: TEST OK [0.005 secs, 3496 KB] All tests OK.
*/
#include <iostream>
#include <fstream>
#include <stdlib.h>
using namespace std; //旋转90度的操作
int **transiformation_one(int before[][],int n){
int **tran = new int*[];
for(int i = ;i < ;i++){
tran[i] = new int[];
}
for(int i = ;i < n;i++)
for(int j = ;j < n;j ++){
tran[j][n-i-] = before[i][j];
}
return tran;
} //旋转180由两次旋转90度得到
int **transiformation_two(int before[][],int n){
int **tran_1 = transiformation_one(before,n);
int temp[][];
for(int i = ;i < n;i++)
for(int j = ;j < n;j ++)
temp[i][j] = tran_1[i][j];
int **tran_2 = transiformation_one(temp,n);
return tran_2;
} //旋转270由三次旋转90度得到
int **transiformation_three(int before[][],int n){
int **tran_1 = transiformation_one(before,n);
int temp[][];
for(int i = ;i < n;i++)
for(int j = ;j < n;j ++)
temp[i][j] = tran_1[i][j]; int **tran_2 = transiformation_one(temp,n);
for(int i = ;i < n;i++)
for(int j = ;j < n;j ++)
temp[i][j] = tran_2[i][j]; int **tran_3 = transiformation_one(temp,n);
return tran_3;
} //沿竖直方向翻转
int **transiformation_four(int before[][],int n){
int **tran = new int*[];
for(int i = ;i < ;i++){
tran[i] = new int[];
} for(int j = ;j <= n/;j++){
for(int i = ;i < n;i ++){
tran[i][n-j-] = before[i][j];
tran[i][j] = before[i][n-j-];
}
}
return tran;
} //判断两个矩阵是否相等
bool is_equal(int **tran,int after[][],int n){
for(int i = ;i < n;i ++)
for(int j = ;j < n;j ++)
if(tran[i][j] != after[i][j]){
return false;
}
return true;
} //没办法统一int**和inta[][11],只好写两个判断相等函数
bool another_equal(int tran[][],int after[][],int n){
for(int i = ;i < n;i ++)
for(int j = ;j < n;j ++)
if(tran[i][j] != after[i][j])
return false;
return true;
} int main(){
ifstream cin("transform.in");
ofstream cout("transform.out"); int n;
char a;
int before[][];
int after[][]; cin >> n;
for(int i = ;i < n;i++)
for(int j = ;j < n;j++){
cin >> a;
if(a == '@')
before[i][j] = ;
else
before[i][j] = ;
} for(int i = ;i < n;i++)
for(int j = ;j < n;j++)
{
cin >> a;
if(a == '@')
after[i][j] = ;
else
after[i][j] = ;
} int **tran = transiformation_one(before,n);
if(is_equal(tran,after,n))
{
cout <<<<endl;
free(tran);
return ;
} tran = transiformation_two(before,n);
if(is_equal(tran,after,n))
{
cout <<<<endl;
free(tran);
return ;
} tran = transiformation_three(before,n);
if(is_equal(tran,after,n))
{
cout <<<<endl;
free(tran);
return ;
} tran = transiformation_four(before,n);
if(is_equal(tran,after,n))
{
cout <<<<endl;
free(tran);
return ;
} //组合操作,调用多个函数实现
tran = transiformation_four(before,n); int temp[][];
for(int i = ;i < n;i++)
for(int j = ;j < n;j ++)
temp[i][j] = tran[i][j];
int **tran_2 = transiformation_one(temp,n); if(is_equal(tran_2,after,n))
{
cout <<<<endl;
free(tran);
free(tran_2);
return ;
}
else{
tran_2 = transiformation_two(temp,n);
if(is_equal(tran_2,after,n))
{
cout <<<<endl;
free(tran);
free(tran_2);
return ;
}
}
tran_2 = transiformation_three(temp,n);
if(is_equal(tran_2,after,n))
{
cout <<<<endl;
free(tran);
free(tran_2);
return ;
} if(another_equal(before,after,n))
{
cout << <<endl;
return ;
} cout <<<<endl;
return ; }

【USACO】Transformations的更多相关文章

  1. 【USACO】Transformations(模拟)

    Transformations A square pattern of size N x N (1 <= N <= 10) black and white square tiles is ...

  2. POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 【USACO】距离咨询(最近公共祖先)

    POJ 1986 Distance Queries / UESTC 256 Distance Queries / CJOJ 1129 [USACO]距离咨询(最近公共祖先) Description F ...

  3. 1642: 【USACO】Payback(还债)

    1642: [USACO]Payback(还债) 时间限制: 1 Sec 内存限制: 64 MB 提交: 190 解决: 95 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 &quo ...

  4. 1519: 【USACO】超级书架

    1519: [USACO]超级书架 时间限制: 1 Sec 内存限制: 64 MB 提交: 1735 解决: 891 [提交] [状态] [讨论版] [命题人:外部导入] 题目描述 Farmer Jo ...

  5. Java实现【USACO】1.1.2 贪婪的礼物送礼者 Greedy Gift Givers

    [USACO]1.1.2 贪婪的礼物送礼者 Greedy Gift Givers 题目描述 对于一群要互送礼物的朋友,你要确定每个人送出的礼物比收到的多多少(and vice versa for th ...

  6. 【CPLUSOJ】【USACO】【差分约束】排队(layout)

    [题目描述] Robin喜欢将他的奶牛们排成一队.假设他有N头奶牛,编号为1至N.这些奶牛按照编号大小排列,并且由于它们都很想早点吃饭,于是就很可能出现多头奶牛挤在同一位置的情况(也就是说,如果我们认 ...

  7. 【USACO】Dining

    [题目链接] [JZXX]点击打开链接 [caioj]点击打开链接 [算法] 拆点+网络流 [代码] #include<bits/stdc++.h> using namespace std ...

  8. 【USACO】Optimal Milking

    题目链接 :        [POJ]点击打开链接        [caioj]点击打开链接 算法 : 1:跑一遍弗洛伊德,求出点与点之间的最短路径 2:二分答案,二分”最大值最小“ 3.1:建边,将 ...

  9. 【USACO】 Balanced Photo

    [题目链接] 点击打开链接 [算法] 树状数组 [代码] #include<bits/stdc++.h> using namespace std; int i,N,ans,l1,l2; ] ...

随机推荐

  1. android开发 wifi开发不稳定性测试

    场景:工厂定制机器,要求一个设备创建wifi热点,一个设备去连接.但是现在发现wifi连接很不稳定,主要以下3方面: 1.连接之前,不容易连接上 2.连接上之后,连不到外网 3.连接上之后,稳定性不好 ...

  2. ZBar之自定义二维码扫描

    // // YvanQRCodeViewController.m // zBar // // Created by City--Online on 15/6/8. // Copyright (c) 2 ...

  3. 1. ProGit-起步

    (1) 版本控制 本地式 大都是采用数据库记录文件的差异 典型的有rcs,主要保存并管理文件补丁,根据补丁去计算各版本文件内容 缺点:无法协同工作 集中式 通过一个单一的集中服务器去管理所有文件的修订 ...

  4. 通过XMLHttpRequest和jQuery实现ajax的几种方式

    AJAX大家已经都知道了,是为了实现异步通讯,提高用户体验度,而将很多旧知识(XML,DOM,JavaScript,HTML,Jquery,Css……)重新融合的一个新的知识框架.而,XMLHttpR ...

  5. 【BZOJ】【2005】【NOI2010】能量采集

    欧拉函数 玛雅,我应该先看看JZP的论文的……贾志鹏<线性筛法与积性函数>例题一 这题的做法……仔细想下可以得到:$ans=2*\sum_{a=1}^n\sum_{b=1}^m gcd(a ...

  6. win7 IIS7 PHP环境配置

    PHP5.2.17 官方下载: http://windows.php.net/downloads/releases/php-5.2.17-Win32-VC6-x86.zip PHP5.3.5 官方下载 ...

  7. .Net 命名(委托,事件==)

    委托及参数命名: public delegate void ClickedEventHandler(object sender, ClickedEventArgs e); ClickedEventHa ...

  8. mvc从xheditor编辑器中获取内容时存在潜在危险

    xmfdsh在使用xheditor提交要发布的文章等内容的时候出现了如下的错误: 从客户端(Content="<p style="text-align...")中检 ...

  9. C++中static的全部作用

    要理解static,就必须要先理解另一个与之相对的关键字,很多人可能都还不知道有这个关键字,那就是auto,其实我们通常声明的不用static修饰的变量,都是auto的,因为它是默认的,就象short ...

  10. hadoop-ha QJM架构应用故障总结

    部署hadoop-ha QJM架构过程我就不说了,参考 我的博客:hadoop-ha QJM架构部署故障一:    namenode 报错日志如下: WARN org.apache.hadoop.hd ...