UVA-253 Cube painting

题目来源:https://cn.vjudge.net/problem/UVA-253

UVA-253 Cube painting

We have a machine for painting cubes. It is supplied with threedifferent colors: blue, red and green. Each face of the cube gets oneof these colors. The cube’s faces are numbered as in Figure 1.Since a cube has 6 faces, our machine can paint a face-numberedcube in 36 = 729 different ways. When ignoring the face-numbers,the number of different paintings is much less, because a cube canbe rotated. See example below.We denote a painted cube by a string of 6 characters, where eachcharacter is a ‘b’, ‘r’, or ‘g’. The i-th character (1 ≤ i ≤ 6) from theleft gives the color of face i. For example, Figure 2 is a picture of“rbgggr” and Figure 3 corresponds to “rggbgr”. Notice that bothcubes are painted in the same way: by rotating it around the verticalaxis by 90°, the one changes into the other.



Input

The input of your program is a textfile that ends with the standard end-of-file marker. Each line is astring of 12 characters. The first 6 characters of this string are the representation of a painted cube, theremaining 6 characters give you the representation of another cube. Your program determines whetherthese two cubes are painted in the same way, that is, whether by any combination of rotations one canbe turned into the other. (Reflections are not allowed.)

Output

The output is a file of boolean. For each line of input, output contains ‘TRUE’ if the second half can beobtained from the first half by rotation as describes above, ‘FALSE’ otherwise.

Sample Input

rbgggrrggbgr

rrrbbbrrbbbr

rbgrbgrrrrrg

Sample Output

TRUE

FALSE

FALSE


题意:1个骰子有六个面,用三种颜色上色,现有两个这题的骰子,问是否是一样的?

分析:两个对面匹配?开始是这么想的,然后抱着一试的心态交了一次,竟然AC了。

当后来队友和我说这样是不行,并且给出了一组反例,说只能24中情况模拟,自己懒就没有重打了

反例:

rbbgrggbgrrb(这个是FALSE)

“AC”的代码:

#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	bool v[4];
	vector<pair<char,char> >a,b,c;
	while(cin>>s)
	{
		a.clear();b.clear();c.clear();
		memset(v,false,sizeof(v));
		//将对边存入 
		a.push_back(make_pair(s[0],s[5]));
		a.push_back(make_pair(s[1],s[4]));
		a.push_back(make_pair(s[2],s[3]));
		b.push_back(make_pair(s[6],s[11]));
		b.push_back(make_pair(s[7],s[10]));
		b.push_back(make_pair(s[8],s[9]));
		c.push_back(make_pair(s[11],s[6]));
		c.push_back(make_pair(s[10],s[7]));
		c.push_back(make_pair(s[9],s[8]));
		/*
for(int i=0;i<3;i++)
		{
			cout<<a[i].first<<a[i].second<<endl;	
		}
		for(int i=0;i<3;i++)
		{
			cout<<b[i].first<<b[i].second<<endl;
			
		}	*/
		int f=0;
		//寻找对边是否匹配 
		for(int i=0;i<3;i++)
		{
			f=1;
			for(int j=0;j<3;j++)
			{
				if((a[i]==b[j]||a[i]==c[j])&&!v[j])
				{
					f=0;
					v[j]=true;
					break;	
				}
			}
			if(f)break;
		}
		if(f) puts("FALSE");
		else puts("TRUE");
		
	}
} 

队友的代码(直接暴力):

#include<stdio.h>
#include<string.h>
int a[3][6]={5,1,3,4,6,2,4,2,1,6,5,3,1,3,5,2,4,6};
char b[100][6];
char c[14],d[10];
int s;
int flag;
void zhuan(int r)
{
	int j;
	for(j=0;j<6;j++)
	{
		if(s)
		b[s][j]=b[s-1][a[r][j]-1];
		else
		b[s][j]=c[a[r][j]-1];
	}
	b[s][6]='\0';
	if(strcmp(b[s],d)==0)
	{
		flag=1;
	}
	s++;
}
int main()
{
	int i,j,k,l;
	while(~scanf("%s",c))
	{
		flag=0;
		for(i=6;i<12;i++)
		{
			d[i-6]=c[i];
		}
		d[6]='\0';
		s=0;
		for(i=0;i<4;i++)
		{
			for(k=0;k<4;k++)
			{
				for(l=0;l<4;l++)
				{
					if(flag)break;
					zhuan(2);
				}
				if(flag)break;
				zhuan(1);
			}
			if(flag)break;
			zhuan(0);
		}
		if(flag)puts("TRUE");
		else puts("FALSE");
	}
}


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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值