六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 25|回复: 0

【水题】USACO Transformations

[复制链接]

升级  68.4%

272

主题

272

主题

272

主题

进士

Rank: 4

积分
842
 楼主| 发表于 2013-1-26 13:31:28 | 显示全部楼层 |阅读模式
进入USACO要注册才能看题: http://train.usaco.org/usacogate

题目:【翻译版、是别处的网站】http://www.wzoi.org/usaco/13%5C408.asp

SAMPLE INPUT (file transform.in)
3
@-@
---
@@-
@-@
@--
--@
SAMPLE OUTPUT (file transform.out)
1


水题……未能一次A……而且一开始还理解错题意……悲催


/*ID: 1006100071PROG: transformLANG: C++*/#include <iostream>#include <fstream>#include <algorithm>#include <string>#include <set>//#include <map>#include <queue>#include <utility>#include <iomanip>#include <stack>#include <list>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <cmath>#include <ctime>#include <ctype.h>using namespace std;bool match (char a[][15], char b[][15], int n)//检查是否匹配{int i;for (i = 0; i < n; i++)if (strcmp (a, b))return false;return true;}void copy (char a[][15], char b[][15], int n)//b复制到a{int i;for (i = 0; i < n; i++)strcpy (a, b);}void _90right (char a[][15], int n)//对a进行90度右转{int i, j;char b[15][15];for (i = 0; i < n; i++){for (j = 0; j < n; j++){b[j][n-1-i] = a[j];b[j][n] = 0;}}for (i = 0; i < n; i++)strcpy (a, b);}void reflect (char a[][15], int n)//对a进行镜面反射{char b[15][15];int i, j;for (i = 0; i < n; i++){for (j = n - 1; j >= 0; j--)b[n-1-j] = a[j];b[n] = 0;}for (i = 0; i < n; i++)strcpy (a, b);}int main(){/*freopen ("transform.in", "r", stdin);freopen ("transform.out", "w", stdout);*/char before[15][15], after[15][15], tp[15][15];int n, i;scanf ("%d", &n);for (i = 0; i < n; i++)scanf ("%s", before+i);for (i = 0; i < n; i++)scanf ("%s", after+i);//**************************右转3种情况:90 180 270copy (tp, before, n);for (i = 1; i <= 3; i++){_90right (tp, n);if (match (tp, after, n)){printf ("%d\n", i);return 0;}}//**************************镜面翻转,也就是水平翻转copy (tp, before, n);reflect (tp, n);if (match (tp, after, n)){puts ("4");return 0;}//**************************镜面+旋转copy (tp, before, n);reflect (tp, n);for (i = 1; i <= 3; i++){_90right (tp, n);if (match (tp, after, n)){puts ("5");return 0;}}//**************************本来就跟原来一样if (match (before, after, n)){puts ("6");return 0;}puts ("7");//方法编号必须要从小到大一次判断,才能保证所得编号最小return 0;}
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表