USACO Section 1.2.3 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


思路

思路很简单,就是枚举各种转换方法,然后与莫状态进行比较。
繁琐即需要注意的是,对于每种转换方式 i和j的关系,稍有疏忽就会全军覆没
另外注意的就是:如果初末状态相同,不能直接输出6,要先看看之前的5种方法能不能得到。因为题目要求从小号优先。我就被坑了一次。

代码

/*
ID:zhrln1
PROG:transform
LANG:C++
*/
#include <cstdio>
int n;
typedef struct board{
	char v[11][11];
} Board;
Board a,b;
Board rdboard(int n){
	Board c;
	for (int i(1);i<=n;i++){
		for (int j(1);j<=n;j++){
			scanf("%c",&c.v[i][j]);
		}
		scanf("\n");
	}
	return c;
}
Board change(Board a,int k,int n){
	Board c;
	for (int i(1);i<=n;i++){
		for (int j(1);j<=n;j++){
			switch(k){
				case 1: c.v[i][j]=a.v[n-j+1][i];break;
				case 2: c.v[i][j]=a.v[n+1-i][n+1-j];break;
				case 3: c.v[i][j]=a.v[j][n+1-i];break;
				case 4: c.v[i][j]=a.v[i][n+1-j];break;
			}
		}
	}
	return c;
}
int isequel(Board a,Board b,int n){
	for (int i(1);i<=n;i++){
		for (int j(1);j<=n;j++){
			if (a.v[i][j]!=b.v[i][j]) return 0;
		}
	}
	return 1;
}
int main(){
	freopen("transform.in","r",stdin);
	freopen("transform.out","w",stdout);
	scanf("%d\n",&n);
	a=rdboard(n);
	b=rdboard(n);
	for (int i(1);i<=4;i++){
		Board t=change(a,i,n);
		if (isequel(t,b,n)){
			printf("%d\n",i);
			return 0;
		}
		if (i==4){
			for (int j(1);j<=3;j++){
				if (isequel(change(t,j,n),b,n)){
					printf("5\n");
					return 0;
				}
			}
		}
	}
	if (isequel(a,b,n)){
		printf("6\n");
		return 0;
	}
	printf("7\n");
	return 0;
}


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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值