【USACO】Transformations(模拟)
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(模拟)的更多相关文章
- USACO 1.2 Transformations (模拟)
模拟题目,依照题目给定的要求变换图形就可以,变换的优先级依次减小. 这个题目我写的非常乱.只是最还还是勉强能够执行 /* ID:twd30651 PROG:transform LANG:C++ */ ...
- Milking Cows 挤牛奶 USACO 排序 模拟
1005: 1.2.1 Milking Cows 挤牛奶 时间限制: 1 Sec 内存限制: 128 MB提交: 15 解决: 9[提交] [状态] [讨论版] [命题人:外部导入] 题目描述 1 ...
- usaco Transformations
模拟就行.注意int arr[][]二维数组在定义时是二维数组,而函数传参时是指针.这意味着memset()的不同.传参时只能当作一维逐个memset. #include <iostream&g ...
- Transformations 方块转换 USACO 模拟 数组 数学 耐心
1006: 1.2.2 Transformations 方块转换 时间限制: 1 Sec 内存限制: 128 MB提交: 10 解决: 7[提交] [状态] [讨论版] [命题人:外部导入] 题目 ...
- USACO 1.3... 虫洞 解题报告(搜索+强大剪枝+模拟)
这题可真是又让我找到了八数码的感觉...哈哈. 首先,第一次见题,没有思路,第二次看题,感觉是搜索,就这样写下来了. 这题我几乎是一个点一个点改对的(至于为什么是这样,后面给你看一个神奇的东西),让我 ...
- Your Ride Is Here 你的飞碟在这儿 USACO 模拟
1001: 1.1.1 Your Ride Is Here 你的飞碟在这儿 时间限制: 1 Sec 内存限制: 128 MB提交: 9 解决: 9[提交] [状态] [讨论版] [命题人:外部导入 ...
- 【USACO】Transformations
A square pattern of size N x N (1 <= N <= 10) black and white square tiles is transformed into ...
- USACO The Tamworth Two 模拟
一道模拟题不过要担心的是牛或者人在转弯的时候,另一方如果能走,那么要走,不能停留. 还是蛮简单的. 调试输出的话可以看到具体追击过程 Source Code: /* ID: wushuai2 PROG ...
- USACO Runaround Numbers 模拟
根据题意的 Runaround 规则去找比当前数大的最近的一个 Runaround数字 模拟题~ Source code: /* ID: wushuai2 PROG: runround LANG: C ...
随机推荐
- 用ccproxy + stunnel做个加密代理
https://www.stunnel.org/downloads.html ccproxy + stunnel做个加密http代理和socks5代理 目前国内用户无法访问某些国外网站,如http:/ ...
- TRIM函数
Trim() 删除字符串首尾的空白(可以首尾一起,也可以指定首或尾,取决于控制参数),但会保留字符串内部作为词与词之间分隔的空格.
- 改变input默认选中颜色
修改 outline-color 属性即可实现
- nginx应用总结(1)--基础认识和应用配置
在linux系统下使用nginx作为web应用服务,用来提升网站访问速度的经验已五年多了,今天在此对nginx的使用做一简单总结. 一.nginx服务简介Nginx是一个高性能的HTTP和反向代理服务 ...
- js jquery 关闭弹出页面 并刷新父页面(window.opener)
function Closepage() { if (window.opener && !window.opener.closed) { window.parent.opener.lo ...
- IO调度器(二) IO的中断返回
IO的中断返回也是相当让人激动的一件事情: 28470 1) | handle_irq() { 28471 1) 0.237 us | ...
- ASP.NET中处理自定义错误的最佳方式
要在ASP.NET中处理好自定义错误(Custom Errors)首先要抛弃使用web.config\customErrors. <customErrors mode="RemoteO ...
- android 混淆文件proguard.cfg详解
-optimizationpasses 5 [代码压缩级别]-dontusemixedcaseclassnames [混淆时不会产生形形色色的类名 ]-dontskipnonpubliclibrar ...
- NFine的后台源码
Chloe官网及基于NFine的后台源码毫无保留开放 扯淡 经过不少日夜的赶工,Chloe 的官网于上周正式上线.上篇博客中LZ说过要将官网以及后台源码都会开放出来,为了尽快兑现我说过的话,趁周末 ...
- linux不同角色server分区方案
服务器角色 分区建议 优点 RAID方案 单机服务器 如8G内存,300G硬盘 /boot 100-200M swap 16G,内存大小8G*2 / 80G /var 20G(也可 ...