码迷,mamicode.com
首页 > 其他好文 > 详细

UVA - 253 Cube painting

时间:2015-04-10 09:39:29      阅读:159      评论:0      收藏:0      [点我收藏+]

标签:

Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu

 Status

Description

技术分享

We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube‘s faces are numbered as in Figure 1.

技术分享

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in 技术分享 different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a b, r, or g. The 技术分享 character ( 技术分享 ) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis 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 a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be 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 be obtained from the first half by rotation as describes above, FALSE otherwise.

Sample Input

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

Sample Output

TRUE
FALSE
FALSE

就是固定向上和下面不变,旋转其余四个面,每次改变向上的面,就会枚举所有6*4个不同的姿态,再与第二个骰子比较,要点空间想象力,不行拿个称手的东西比划下就出来了,还有旋转时注意下姿态。

#include<iostream>
#include<cstring>
#include<string>
#include<cstdio>
using namespace std;   //列出不同面朝上是各个位置的数字
int dir[6][6] = { { 0, 1, 2, 3, 4, 5 }, { 1, 0, 3, 2, 5, 4 }, { 2, 0, 1, 4, 5, 3 }, { 3, 0, 4, 1, 5, 2 }, { 4, 0, 2, 3, 5, 1 }, { 5, 1, 3, 2, 4, 0 } };
char a[10];
char b[10];
char s[20];
bool judge()
{
	for (int i = 0; i < 6; i++)
	{
		char temp[10] = "";
		for (int j = 0; j < 6; j++)  //置骰子姿态分别为各个不同数字向上
			temp[j] = a[dir[i][j]];
		for (int j = 0; j < 4; j++)
		{
			char c_temp;
			c_temp = temp[1];  //旋转,注意yy出旋转是数字变化的方式
			temp[1] = temp[2];
			temp[2] = temp[4];
			temp[4] = temp[3];
			temp[3] = c_temp;
			if (strcmp(temp, b) == 0) return true;
		}
	}
	return false;
}
int main()
{
	while (scanf("%s", s) != EOF)
	{
		for (int i = 0; i < 6; i++)
			a[i] = s[i];
		a[6] = 0;
		for (int i = 0; i < 6; i++)
			b[i] = s[i + 6];
		b[6] = 0;
		if (judge()) cout << "TRUE" << endl;
		else cout << "FALSE" << endl;
	}
}


UVA - 253 Cube painting

标签:

原文地址:http://blog.csdn.net/qq_18738333/article/details/44968341

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!