基德KID.1412 发表于 2013-1-26 13:31:28

【水题】USACO Transformations

进入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[], char b[], int n)//检查是否匹配{int i;for (i = 0; i < n; i++)if (strcmp (a, b))return false;return true;}void copy (char a[], char b[], int n)//b复制到a{int i;for (i = 0; i < n; i++)strcpy (a, b);}void _90right (char a[], int n)//对a进行90度右转{int i, j;char b;for (i = 0; i < n; i++){for (j = 0; j < n; j++){b = a;b = 0;}}for (i = 0; i < n; i++)strcpy (a, b);}void reflect (char a[], int n)//对a进行镜面反射{char b;int i, j;for (i = 0; i < n; i++){for (j = n - 1; j >= 0; j--)b = a;b = 0;}for (i = 0; i < n; i++)strcpy (a, b);}int main(){/*freopen ("transform.in", "r", stdin);freopen ("transform.out", "w", stdout);*/char before, after, tp;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;}
页: [1]
查看完整版本: 【水题】USACO Transformations