UVa 253: Cube painting

这道题要我们判断对于一个立方体用三种颜色染色(可以只使用其中的一种或两种颜色),题目所给的两种染色方案本质上是否相同(即立方体经过翻转后可重合)。

对于这道题,我们只要枚举出第一种染色方案下的立方体所有能够通过翻转产生的其他本质相同的染色方案,与第二种方案比较就可以得到结果。

即枚举立方体绕X,Y,Z轴旋转后的结果(三个轴均可以绕着旋转0度,90度,180度,270度),最多4^3=64中情况。

我的解题代码如下:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <string>
#include <algorithm>

using namespace std;
const int X_rotate[4][6]
= { 1, 2, 3, 4, 5, 6,
	3, 2, 6, 1, 5, 4,
	6, 2, 4, 3, 5, 1,
	4, 2, 1, 6, 5, 3
};
const int Y_rotate[4][6]
= { 1, 2, 3, 4, 5, 6,
	5, 1, 3, 4, 6, 2,
	6, 5, 3, 4, 2, 1,
	2, 6, 3, 4, 1, 5
};
const int Z_rotate[4][6]
= { 1, 2, 3, 4, 5, 6,
	1, 4, 2, 5, 3, 6,
	1, 5, 4, 3, 2, 6,
	1, 3, 5, 2, 4, 6
};
char s[16],s1[8],s2[8],s3[8];
int main()
{
	while(cin >> s)
	{
		int ok=0;
		for(int i=0; i<4; i++) if(!ok)
		{
			for(int t=0; t<6; t++) s1[t]=s[X_rotate[i][t]-1];
			for(int j=0; j<4; j++) if(!ok)
			{
				for(int t=0; t<6; t++) s2[t]=s1[Y_rotate[j][t]-1];
				for(int k=0; k<4; k++) if(!ok)
				{
					for(int t=0; t<6; t++) s3[t]=s2[Z_rotate[k][t]-1];
					int ok2=1;
					for(int t=0; t<6; t++) if(s3[t]!=s[t+6]){ ok2=0; break;}
					if(ok2) ok=1;
				}
			}
		}
		if(ok) cout << "TRUE\n";
		else cout << "FALSE\n";
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值