uva 253 Cube painting

 Cube painting 

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

最简单的方法,穷举
 1 #include <iostream>
 2 using namespace std;
 3 char s[13];
 4
 5 //判断五个面即可(剩下一个确定)
 6 int judge(char c1,char c2,char c3,char c4,char c5)
 7 {             //第一个数的面固定,旋转有四种情况
 8     if(c1==s[6]&&c2==s[7]&&c3==s[8]&&c4==s[9]&&c5==s[10])return 1;
 9     if(c1==s[6]&&c2==s[9]&&c3==s[7]&&c4==s[10]&&c5==s[8])return 1;
10     if(c1==s[6]&&c2==s[10]&&c3==s[9]&&c4==s[8]&&c5==s[7])return 1;
11     if(c1==s[6]&&c2==s[8]&&c3==s[10]&&c4==s[7]&&c5==s[9])return 1;
12     return 0;
13 }
14 int main()
15 {
16     while(cin>>s){
17         int x1,x2,x3,x4,x5,x6;
18         x1=judge(s[0],s[1],s[2],s[3],s[4]);   //各个不同的面放在第一个数
19         x2=judge(s[1],s[5],s[2],s[3],s[0]);
20         x3=judge(s[2],s[4],s[0],s[5],s[1]);
21         x4=judge(s[3],s[1],s[0],s[5],s[4]);
22         x5=judge(s[4],s[0],s[2],s[3],s[5]);
23         x6=judge(s[5],s[4],s[2],s[3],s[1]);
24         if(x1+x2+x3+x4+x5+x6)cout<<"TRUE"<<endl;
25         else cout<<"FALSE"<<endl;
26     }
27     return 0;
28 }
时间: 2024-10-10 15:19:48

uva 253 Cube painting的相关文章

uva 253 - Cube painting(相同骰子)

习题4-4 骰子涂色(Cube painting, UVa 253) 输入两个骰子,判断二者是否等价.每个骰子用6个字母表示,如图4-7所示. 图4-7 骰子涂色 例如rbgggr和rggbgr分别表示如图4-8所示的两个骰子.二者是等价的,因为图4-8(a) 所示的骰子沿着竖直轴旋转90°之后就可以得到图4-8(b)所示的骰子. (a) (b) 图4-8 旋转前后的两个骰子 . Sample Input rbgggrrggbgr rrrbbbrrbbbr rbgrbgrrrrrg Sample

UVA 253 Cube painting(枚举 模拟)

题意: 按如图的顺序给定2个骰子的颜色(只有r.b.g三种颜色) 问2个骰子是否一模一样 如 可表示为"rbgggr" 和 "rggbgr", 第二个就是绕着Z轴顺时针旋转90度与第一个相同的骰子. 分析: 记录一个错误的做法:并不是只要两面两面互相映射, 如rbrggb 与 rgrgbb, 即使 rb 对应 rb.gb 对应 bg. rg对应rg, 但他们并不是一模一样的骰子.(可以借助真正的骰子旋转尝试一下,就是123456 和 153426, 想象一下2与5互

UVa 253 Cube paiting

题意:输入两个骰子,判断是否等价 因为每一个面可以作顶面,共6*4种情况,枚举就可以了 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include <cmath> 5 #include<stack> 6 #include<vector> 7 #include<map> 8 #include<queue> 9 #include<

Cube painting UVA 253

说说:一看到给立方体染色,开始还有点小害怕.毕竟高中数学里染色问题从来都不会简单.这道题的意思就是给立方体的六个面染色,然后判断两个染了色的立方体是否一样.其实仔细一想,立方体无非三对面,若开始确定两对面.如下面图Figure 1所示:假设1,2,6,5这四个面先确定(这只有唯一一种情况)之后,再放3,4,的时候无非两种情况.但这两种情况是不一样的,这也许就是题目所说的reflection.开始的想法是找出三对面,然后比较是否相等即可,不过实在想不出怎样来排除reflection的情况.所以只能

UVA253 Cube painting【置换】

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. ????Since a cube has 6 faces, our machine can paint a

uva253 Cube painting(UVA - 253)

题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相同的面并且他们的对面相等那么继续寻找,直到三个面都能找到相对立的面 ③如果有一个面没有找到相等的面或者相等的对面之类的那么就break循环然后直接判断FALSE如果三个面都能满足上述条件,那么就是TRUE 代码 #include <bits/stdc++.h> using namespace st

UVa 253 骰子涂色

https://vjudge.net/problem/UVA-253 题意:输入两个骰子的六面颜色,判断是否等价. 思路:我最想到的是暴力,不过一直错,也不知道哪里错了.第二种方法就是在一个骰子里出现的一对颜色在第二个骰子也有,只要三对颜色都匹配成功,那么就是等价的. 1 #include<iostream> 2 #include<string> 3 #include<cstring> 4 using namespace std; 5 6 char str[20]; 7

UVa 253

背景:一次编译通过加一次ac就是这么爽!!!!!! 思路:枚举六个面朝上,每种情况旋转4次的所有情况,一共24种,全部枚举出来比较即可!这里比较巧妙的是把每一种情况都写作一个长度为6的字符串,并在第七位加一个'\0 ',这样就可以用strcmp来比较了. #include<stdio.h> #include<string.h> int main(void){ char l[7],r[7],temp[13]; l1: while(~scanf("%s",temp)

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes