Transformations USACO

原题地址

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
/*
ID : liuming9
LANG : C++
TASK: transform
*/
#include <cstdio>
#include <string.h>

int main(){
	freopen("transform.in", "r", stdin);
	freopen("transform.out", "w", stdout);
	int n;
	//a保存第一个矩阵,b保存a的镜像
	char a[11][11], b[11][11], c;
	bool mar[10];
	memset(mar, true, sizeof(mar));
	scanf("%d", &n);
	getchar();
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			b[i][n + 1 - j] = a[i][j] = getchar();
		}
		getchar();
	}
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= n; j++){
			c = getchar();
			if(c != a[n + 1 - j][i])
				mar[1] = false;
			if(c != a[n + 1 - i][n + 1 - j])
				mar[2] = false;
			if(c != a[j][n + 1 - i])
				mar[3] = false;
			if(c != b[i][j])
				mar[4] = false;
			if(c != b[n + 1 - j][i])
				mar[5] = false;
			if(c != b[n + 1 - i][n + 1 - j])
				mar[6] = false;
			if(c != b[j][n + 1 - i])
				mar[7] = false;
			if(c != a[i][j])
				mar[8] = false;
		}
		getchar();
	}
	for(int i = 1; i <= 4; i++)
		if(mar[i]){
			printf("%d\n", i);
			return 0;
		}
	if(mar[5] || mar[6] || mar[7]){
		puts("5");
		return 0;
	}
	if(mar[8]){
		puts("6");
		return 0;
	}
	puts("7");
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值