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

遇到了小问题,就是本地和USACO结果不一样,原来是少了句return。

/*
USER: RAO WENJIN
TASK: transform
LANG: C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#define N 15
using namespace std;
char s[][N][N];
int n,op;
void rot(char s[][N],int times){
char t[N][N];
memset(t,,sizeof t);
for(int i=;i<=times;i++){
for(int i=;i<n;i++)
for(int j=;j<n;j++)
t[j][n-i-]=s[i][j];
memcpy(s,t,sizeof t);
}
}
void refl(char s[][N]){
for(int i=;i<n;i++)
for(int j=;j<n/;j++)
swap(s[i][n-j-],s[i][j]);
}
int ck(){
for(int i=;i<n;i++)
for(int j=;j<n;j++)
if(s[][i][j]!=s[][i][j])return ;
return ;
}
int work(int op){
if(op==)rot(s[],);
if(op==)rot(s[],);
if(op==)rot(s[],);
if(op==)rot(s[],),refl(s[]);
if(op==){
for(int i=;i<;i++){
rot(s[],);
if(ck())return ;
}
return ;//这句漏了
}
return ck();
}
int main(){
freopen("transform.in","r",stdin);
freopen("transform.out","w",stdout);
cin>>n;
for(int k=;k<;k++)
for(int i=;i<n;i++)
cin>>s[k][i];
for(op=;op<;op++)
if(work(op)){cout<<op<<endl;break;}
if(op==)cout<<<<endl;
}

【USACO】Transformations(模拟)的更多相关文章

  1. USACO 1.2 Transformations (模拟)

    模拟题目,依照题目给定的要求变换图形就可以,变换的优先级依次减小. 这个题目我写的非常乱.只是最还还是勉强能够执行 /* ID:twd30651 PROG:transform LANG:C++ */ ...

  2. Milking Cows 挤牛奶 USACO 排序 模拟

    1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec  内存限制: 128 MB提交: 15  解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...

  3. usaco Transformations

    模拟就行.注意int arr[][]二维数组在定义时是二维数组,而函数传参时是指针.这意味着memset()的不同.传参时只能当作一维逐个memset. #include <iostream&g ...

  4. Transformations 方块转换 USACO 模拟 数组 数学 耐心

    1006: 1.2.2 Transformations 方块转换 时间限制: 1 Sec  内存限制: 128 MB提交: 10  解决: 7[提交] [状态] [讨论版] [命题人:外部导入] 题目 ...

  5. USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)

    这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...

  6. Your Ride Is Here 你的飞碟在这儿 USACO 模拟

    1001: 1.1.1 Your Ride Is Here 你的飞碟在这儿 时间限制: 1 Sec  内存限制: 128 MB提交: 9  解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...

  7. 【USACO】Transformations

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

  8. USACO The Tamworth Two 模拟

    一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留. 还是蛮简单的. 调试输出的话可以看到具体追击过程 Source Code: /* ID: wushuai2 PROG ...

  9. USACO Runaround Numbers 模拟

    根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C ...

随机推荐

  1. js继承《转》

    http://www.jb51.net/article/55540.htm http://www.cnblogs.com/OceanHeaven/p/4965947.html http://www.j ...

  2. C#输出log信息

    在写程序的过程中,有时候我们需要添加一些log信息,这个时候,可以采用下面的方法来实现. public static void WriteLog(string ExtraMsg, Exception ...

  3. Javascript中document.execCommand()的用法

    document.execCommand()方法处理Html数据时常用语法格式如下:document.execCommand(sCommand[,交互方式, 动态参数]) 其中:sCommand为指令 ...

  4. QTableView 一列添加两个按钮

    在QTableView的一列里添加两个按钮,之前添加一个按钮的思路是一样的,只是计算了一下按钮的宽,放两个按钮而已. 添加一个按钮的例子:QTableView 添加按钮 本例源代码:QtTowButt ...

  5. bootstrap-datepicker带中文的js文件

    ) { $(".datepicker").datepicker({ language: "zh-CN", autoclose: true,//选中之后自动隐藏日 ...

  6. grootjs 简明教程

    grootJs简明教程 mvvm框架也是解决的一类问题,在某些时候会提高生产效率: 经过接近一个月的努力,grootJs测试版终于发布了 grootJs是一个mvvm的框架,名字取 grass 和ro ...

  7. PHP 实现页面静态化

    PHP文件执行阶段:语法分析->编译->运行 静态html文件执行顺序:运行 动态程序: 连接数据库服务器或者缓存服务器->获取数据->填充到模板->呈现给用户 关于优化 ...

  8. sprintf_s的教训

    sprintf_s 是个比sprintf更安全的函数,今天在使用的过程中犯了个错误,代码的大致意思如下 void Test_sprintf_s() { ]; memset(buff, , sizeof ...

  9. 基于FPGA的音频信号的FIR滤波(Matlab+Modelsim验证)

    1 设计内容 本设计是基于FPGA的音频信号FIR低通滤波,根据要求,采用Matlab对WAV音频文件进行读取和添加噪声信号.FFT分析.FIR滤波处理,并分析滤波的效果.通过Matlab的分析验证滤 ...

  10. social emotion computing-感情的分类

    第八节  情感的分类 人的情感复杂多样,可以从不同的观察角度进行分类.由于情感的核心内容是价值,因此人的情感主要必须根据它所反映的价值关系的运动与变化的不同特点来进行分类. 1.根据价值的正负变化方向 ...