Usaco Training刷怪旅 第二层第二题:Transformations

该博客讨论了一个编程问题,要求编写一个程序来识别将一个方形黑白瓷砖模式转换为另一个模式所需的最小变换。给出了7种可能的变换:旋转90/180/270度,水平反射,反射后再旋转,不变换,以及无效变换。示例输入和输出展示了如何判断变换类型。提供的C++代码实现检查这些变换并输出最小变换编号。
摘要由CSDN通过智能技术生成

usaco training

关注我持续更新usaco training

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 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

 

说实话,这道题出的真的恶心

 

翻译一下:给你两个图案,问你用哪种方法能把第一个图形变成第二个图形,并且方法编号要最小

第一种方法:顺时针旋转90°

第二种方法:顺时针旋转180°

第三种方法:顺时针旋转270°

第四种方法:水平反射

 

第五种:先反射再旋转(1-3种之间的任意一种)

第六种:不做任何改动,本身就一样

第七种:怎么改都不行

如果我们真的按照上述说的一样对图形进行改变的话肯定是不现实的

我们只能按照数组下标进行找规律

第一种:

 

旋转90°

我们找几个位置的下标进行找规律

 

a[i][j]=b[j][n-i+1]

第二种:

b[n-i+1][n-j+1]=a[i][j] 

第三种:

b[n-j+1][i]=a[i][j]; 

第四种:

b[i][n-j+1]=a[i][j]

第五种:

这个没有自己的图了,就是结合起来

把上面的结合起来,就成为了ac代码

函数名自己随便取就行

/*
ID:
TASK:transform
LANG:C++
*/
# include <iostream>
# include <cstdio>
using namespace std;
# define int long long
# define N 15
char fir[N][N],sec[N][N];
int n;
char temp[N][N];
bool zhijiao(){
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			temp[j][n-i+1]=fir[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (temp[i][j]!=sec[i][j]){
				return false;
			}
		}
	}
	return true;
}
bool pingjiao(){
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			temp[n-i+1][n-j+1]=fir[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (temp[i][j]!=sec[i][j]){
				return false;
			}
		}
	}
	return true;
}
bool _270(){
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			temp[n-j+1][i]=fir[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (temp[i][j]!=sec[i][j]){
				return false;
			}
		}
	}
	return true;
}
bool fanshe(){
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			temp[i][n-j+1]=fir[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (temp[i][j]!=sec[i][j]){
				return false;
			}
		}
	}
	return true;
}
bool zuhe(){
	fanshe();
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			fir[i][j]=temp[i][j];
		}
	}
	if (zhijiao()||pingjiao()||_270()){
		return true;
	}
	return false;
}
bool dont(){
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			if (fir[i][j]!=sec[i][j]){
				return false;
			}
		}
	}
	return true;
}
signed main(){
	freopen("transform.in","r",stdin);
	freopen("transform.out","w",stdout);
	scanf("%lld",&n);
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			cin>>fir[i][j];
		}
	}
	for (int i=1;i<=n;i++){
		for (int j=1;j<=n;j++){
			cin>>sec[i][j];
		}
	}
	if (zhijiao()){
		printf("1\n");
		return 0;
	}else if (pingjiao()){
		printf("2\n");
		return 0;
	}else if (_270()){
		printf("3\n");
		return 0;
	}else if (fanshe()){
		printf("4\n");
		return 0;
	}else if (zuhe()){
		printf("5\n");
		return 0;
	}else if (dont()){
		printf("6\n");
		return 0;
	}else{
		printf("7\n");
		return 0;
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}

  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值