`

【水题】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: 1006100071
PROG: transform
LANG: 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[i], b[i]))
			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[i], b[i]);
}
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[i][j];
			b[j][n] = 0;
		}
	}
	for (i = 0; i < n; i++)
		strcpy (a[i], b[i]);
}
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[i][n-1-j] = a[i][j];
		b[i][n] = 0;
	}
	for (i = 0; i < n; i++)
		strcpy (a[i], b[i]);
}
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 270
	copy (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;
}
0
1
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics