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

UVA253Cube painting骰子涂色

时间:2015-04-26 15:04:55      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:

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

输入连个骰子,判断是否等价。

 

 1 #include<iostream>
 2 
 3 using namespace std;
 4            //列举4*6种可能
 5 int a[30][6] =
 6 { {},
 7 { 1, 2, 3, 4, 5, 6 }, { 1, 4, 2, 5, 3, 6 }, { 1, 5, 4, 3, 2, 6 }, { 1, 3, 5, 2, 4, 6 },
 8 { 6, 2, 4, 3, 5, 1 }, { 6, 3, 2, 5, 4, 1 }, { 6, 5, 3, 4, 2, 1 }, { 6, 4, 5, 2, 3, 1 },
 9 { 2, 6, 3, 4, 1, 5 }, { 2, 4, 6, 1, 3, 5 }, { 2, 1, 4, 3, 6, 5 }, { 2, 3, 1, 6, 4, 5 },
10 { 5, 6, 4, 3, 1, 2 }, { 5, 3, 6, 1, 4, 2 }, { 5, 1, 3, 4, 6, 2 }, { 5, 4, 1, 6, 3, 2 },
11 { 3, 2, 6, 1, 5, 4 }, { 3, 1, 2, 5, 6, 4 }, { 3, 5, 1, 6, 2, 4 }, { 3, 6, 5, 2, 1, 4 },
12 { 4, 2, 1, 6, 5, 3 }, { 4, 6, 2, 5, 1, 3 }, { 4, 5, 6, 1, 2, 3 }, { 4, 1, 5, 2, 6, 3 }
13 };
14 
15 int main()
16 {
17     int i, j, n, m, s, t;
18     char s1[20], s2[20];
19     while (cin>>s1)            //输入字符串s1共12位
20     {
21         for (i = 6; i <= 12; i++)  //将 后六位 赋值给s2
22         {
23             s2[i - 6] = s1[i];
24         }
25         for (i = 1; i <= 24; i++)
26         {
27             for (j = 0; j <= 5; j++)
28             {
29                 
30                 if (s2[j] == s1[a[i][j] - 1])
31                 {
32 
33                 }
34                 
35                 else
36                 {
37                     break;   //如果不是一一对应,退出当前循环(最近的那个for循环)
38 } //然后i+1 继续循环
39 } 40 if (j == 6) //j==6说明 这次循环j运行超过六次,存在一一对应。 41 { 42 break; //退出循环 43 } 44 } 45 if (i == 25) //i==25说明循环超过二十四次,未找到一一对应项,False 46 { 47 printf("FALSE\n"); 48 } 49 else 50 { 51 printf("TRUE\n"); 52 } 53 } 54 return 0; 55 }

 



















UVA253Cube painting骰子涂色

标签:

原文地址:http://www.cnblogs.com/ghost-song/p/4457666.html

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