UVA 253 Cube painting
来源:互联网 发布:手机怎么注册淘宝会员 编辑:程序博客网 时间:2024/04/23 15:38
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
rbgggrrggbgrrrrbbbrrbbbrrbgrbgrrrrrg
Sample Output
TRUEFALSEFALSE
做出模型,进行穷举!
代码如下:
#include <stdio.h>#include <string.h>int rot[30][10]= { {1,2,3,4,5,6},{1,3,5,2,4,6},{1,4,2,5,3,6},{1,5,4,3,2,6}, {2,6,3,4,1,5},{2,3,1,6,4,5},{2,1,4,3,6,5},{2,4,6,1,3,5}, {3,2,6,1,5,4},{3,1,2,5,6,4},{3,5,1,6,2,4},{3,6,5,2,1,4}, {6,5,3,4,2,1},{6,4,5,2,3,1},{6,3,2,5,4,1},{6,2,4,3,5,1}, {5,1,3,4,6,2},{5,4,1,6,3,2},{5,6,4,3,1,2},{5,3,6,1,4,2}, {4,5,6,1,2,3},{4,6,2,5,1,3},{4,2,1,6,5,3},{4,1,5,2,6,3} };char str2[10];int main(void){ char str1[10]={'\0'}; int i; char str[12]; int turn(char *s); while(scanf("%s",str)!=EOF) { for(i=0;i<6;i++) { str1[i]=str[i]; str2[i]=str[6+i]; } str1[i]='\0'; if(turn(str1)) printf("TRUE\n"); else printf("FALSE\n"); } return 0;} int turn(char *s){ int i,j; char a[30][10]={'\0'}; for(i=0;i<24;i++) { for(j=0;j<6;j++) a[i][j]=s[rot[i][j]-1]; if(!strcmp(str2,a[i])) return 1; } return 0;}
- UVa 253 - Cube painting
- Uva 253 - Cube painting
- Uva 253 Cube Painting
- uva 253 Cube painting
- uva 253 - Cube painting
- UVa 253 - Cube painting
- UVA 253 - Cube painting
- UVA 253 - Cube painting
- UVA 253 Cube painting
- UVa 253: Cube painting
- uva 253 - Cube painting
- uva 253 Cube painting
- UVA 253 Cube painting
- 253 - Cube painting UVA
- UVa 253 Cube painting
- UVA-253-Cube painting
- UVa 253 - Cube painting
- UVA 253 Cube painting
- 总结zkjc
- OpenSSL编程初探2 --- 关于证书文件的加载
- 如何决定自己的未来:浅谈程序猿职业规划
- (3)流程控制语句
- Django配合Javascript国际化
- UVA 253 Cube painting
- 求解矩形的面积和周长
- div边框阴影的实现
- 夜谭hibernate的运行原理
- Unrecognized Windows Sockets error: 0: JVM_Bind 异常解决办法
- OCP-1Z0-053-V12.02-69题
- Android 场景问题总结。(部分转载)
- 如何有效管理自己安装的eclipse插件
- [LeetCode]3sum