UVA253 Cube painting-20140127
来源:互联网 发布:js 限制ip 编辑:程序博客网 时间:2024/04/26 07:04
题目描述
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, FALSEotherwise.
Sample Input
rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg
Sample Output
TRUEFALSEFALSE
解题报告
本题较简单,可我还是花费了大量的时间在如何唯一确定立方体上。
这里,可以直接通过判断对面方向的颜色是否相同来确定。
代码
#include <iostream>#include <cstring>#include <string>#include <cstdio>using namespace std;int face(int i){ switch(i) { case 0:return 5;break; case 1:return 4;break; case 2:return 3;break; case 3:return 2;break; case 4:return 1;break; case 5:return 0;break; }}int main(){ char inpu[14]; while (cin>>inpu) { char cube1[7],cube2[7]; for(int i=0;i<6;i++) { cube1[i]=inpu[i]; cube2[i]=inpu[i+6]; } bool pase[6]={false}; bool same=true; for(int i=0;i<6;i++) { int o; bool th=false; for(o=0;o<=5;o++) { if (cube1[i]==cube2[o]&&pase[o]==false) if(cube1[face(i)]==cube2[face(o)]) {th=true; pase[o]=true; break;} } if(th==false) same=false; } if(same==true) cout<<"TRUE"<<endl; else cout<<"FALSE"<<endl; } return 0;}
- UVA253 Cube painting-20140127
- UVA253 - Cube painting
- UVa253 - Cube painting
- UVA253 Cube painting
- UVA253 Cube painting
- Uva253 Cube painting
- UVA253 Cube Painting
- 水题:UVa253-Cube painting
- UVA253-4.4(ti)-Cube painting
- 算法竞赛入门经典 UVa253 Cube painting
- UVA253——骰子涂色(Cube painting)
- UVa253--Cube painting--骰子涂色--重在算法思想
- UVa253 Cube painting(骰子涂色)(27行,比较简洁的样子)
- [刷题]算法竞赛入门经典(第2版) 4-4/UVa253 - Cube painting
- 算法竞赛入门经典 第二版 习题4-4 骰子涂色 Cube painting uva253
- Cube painting
- Cube painting
- Cube painting
- MySQL嵌入式版本的小程序例子
- 客户端POST发送json数据给服务端,客户端端接收服务器端json数据响应
- Android中资源文件assets和res下面raw文件的使用不同点
- wsgiref 源代码分析
- 架构方法实践 - 客户端CAD工具范例 (二 概念架构部分)
- UVA253 Cube painting-20140127
- python连接hive
- 简略介绍JDK1.7自带的工具
- UVALive - 4256 Salesmen
- 如何成为优秀的驱动开发工程师
- 雷火豊 (易經大意 韓長庚)
- vc2005编译ffmpeg以及ffplay
- C# 发送邮件示例
- 基础开发平台—DataGridView合计行的解决方案