【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 ...
随机推荐
- java 22 - 3 多线程的概述以及其它所涉及的东西(看)
1:要想了解多线程,必须先了解线程,而要想了解线程,必须先了解进程,因为线程是依赖于进程而存在. 2:什么是进程? 通过任务管理器我们就看到了进程的存在. 而通过观察,就可以发现只有运行的程序才会出现 ...
- poj[1185]炮兵阵地
Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组成,地图的每一格可能是山地(用"H" 表示),也可能是平原(用&quo ...
- input file美化,文件上传
此文学习至:http://www.haorooms.com/post/input_file_leixing 然而只会用,不会做,UI泪茫茫 效果图: 原图: 美化后: 此主要用css美化表单,然后用J ...
- redis-cache中的callback
这个是mybatis/redis-cache中关键类 RedisCache 的源码 /** * Copyright 2015 the original author or authors. * * ...
- Structs2配置文件相关说明
1,structs.xml文件解析 <package name="front" namespace="/front" extends="stru ...
- C#.NET 大型通用信息化系统集成快速开发平台 4.0 版本 - 组织机构的名称编号是否允许重复?
通常情况下,一个公司内部的部门名称,编号是不可能重复的.但是是在多公司的情况下,很可能有部门名称重复的问题存在,这时需要允许部门名称重复. 例如一个大型IT公司,在2个地区都有研发部或者客户服务部,这 ...
- AI: Jarvis
AI: Jarvis 扎克伯格本周二在facebook发布了一篇文章,介绍自己利用个人时间开发的一套在自己家里使用的AI系统,并将它命名为Jarvis,对!就是电影钢铁侠里的AI助手Jarvis. ...
- android错误之MediaPlayer用法的Media Player called in state *,androidmediaplayer
用到Media Player,遇到几个问题,记一下 用法就不说了,使用的时候最好参考一下mediaPlayer的这张图 第一个错误是Media Player called in state 8 这个是 ...
- Openwrt dnsmasq 设置要点
之前设置dnsmasq,一直没有奏效,后来摸索了一下,初步发现它的原理: 正常的流程应该是像这样的,先由client来发送DNS请求到网关,然后网关的dnsmasq处理这个请求, 再根据设置决定如何处 ...
- 误人子弟的网络,谈谈HTTP协议中的短轮询、长轮询、长连接和短连接
引言 最近刚到公司不到一个月,正处于熟悉项目和源码的阶段,因此最近经常会看一些源码.在研究一个项目的时候,源码里面用到了HTTP的长轮询.由于之前没太接触过,因此LZ便趁着这个机会,好好了解了一下HT ...