UVAOJ 253-cube painting

这道题的难点在于 如何思考方块的旋转

每个方块不管如何旋转组合最后都只有24种可能。

求出每种可能然后遍历即可。

注意 1与6对,2与5对,3与4对。

而且当某两组(如1,6 跟2,5)固定时,第三组也就固定了,因为有对应关系存在。所以 3*2*2*2*1*1 = 24

#include <stdlib.h>
#include <stdio.h>
#include <string.h>

#define ERROR -1
#define OK 0

int res[][6]={
{ 1, 2, 3, 4, 5, 6 },{ 1, 3, 5, 2, 4, 6 },{ 1, 4, 2, 5, 3, 6 },{ 1, 5, 4, 3, 2, 6 },
{ 2, 1, 4, 3, 6, 5 },{ 2, 3, 1, 6, 4, 5 },{ 2, 4, 6, 1, 3, 5 },{ 2, 6, 3, 4, 1, 5 },
{ 3, 1, 2, 5, 6, 4 },{ 3, 2, 6, 1, 5, 4 },{ 3, 5, 1, 6, 2, 4 },{ 3, 6, 5, 2, 1, 4 },
{ 4, 1, 5, 2, 6, 3 },{ 4, 2, 1, 6, 5, 3 },{ 4, 5, 6, 1, 2, 3 },{ 4, 6, 2, 5, 1, 3 },
{ 5, 1, 3, 4, 6, 2 },{ 5, 3, 6, 1, 4, 2 },{ 5, 4, 1, 6, 3, 2 },{ 5, 6, 4, 3, 1, 2 },
{ 6, 2, 4, 3, 5, 1 },{ 6, 3, 2, 5, 4, 1 },{ 6, 4, 5, 2, 3, 1 },{ 6, 5, 3, 4, 2, 1 }	
};

int cmpArray(char* a, char* b){
	int i;
	for(i=0; i< 6; i++){
		if(a[i] != b[i])
			return -1;	
	}	
	return 0;
}

int pcol(char* s){
	char s1[6]={0};
	char s2[6]={0};
	int i,j;
	for(i=0; i < 6; i++)
		s1[i] = s[i];
	for(i=6; i < 12; i++)
		s2[i-6] = s[i];
	for(i=0;i<24;i++){
		char t[6];
		for(j=0; j<6; j++){
			t[j] = s1[res[i][j]-1];	
		}
		/*printf("%c%c%c%c%c%c\n", t[0],t[1],t[2],t[3],t[4],t[5]);*/
		if(cmpArray(t, s2)==0)
			return 1;	
	}	
	return 0;
}

int main(void){
	char colors[12] = {0};
	while(scanf("%s", colors) != EOF){
		if(pcol(colors))
			printf("TRUE\n");
		else
			printf("FALSE\n");	
	}
	return 0;	
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值