算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 骰子上色Uva253
来源:互联网 发布:近亲结婚知乎 编辑:程序博客网 时间:2024/09/21 09:21
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>#include<stdlib.h>int c1(const void *a,const void *b){ return strcmp((char *)a,(char *)b);}int main(){ char s[13],s1[7]={},s2[7]={},cmp1[3][3]={},cmp2[3][3]={}; int i,j,k,sum=0; while(gets(s)) { for(i=0;i<6;i++) { s1[i]=s[i]; } for(i=6;i<12;i++) { s2[i-6]=s[i]; } for(k=0,i=0,j=5;i<3;i++,j--,k++) { cmp1[k][0]=s1[i]; cmp1[k][1]=s1[j]; } for(k=0,i=0,j=5;i<3;i++,j--,k++) { cmp2[k][0]=s2[i]; cmp2[k][1]=s2[j]; } for(i=0;i<3;i++) { qsort(cmp1[i],2,sizeof(char),c1); qsort(cmp2[i],2,sizeof(char),c1); } for(i=0;i<3;i++) { for(j=0;j<3;j++) { if(strcmp(cmp2[i],cmp1[j])==0&&strcmp(cmp1[j],"00")!=0) { strcpy(cmp2[i],"00"); strcpy(cmp1[j],"00"); sum++; } } } if(sum==3) printf("TRUE\n"); else printf("FALSE\n"); sum=0; }}
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 骰子上色Uva253
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 刽子手游戏
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 发放救济金Uva133
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 信息解码
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 洪水!
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 互联网协议网络Uva1590
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 师兄帮帮忙
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 象棋
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 师兄帮帮忙 Uva12412
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 黑白翻转棋
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 Morse Mismatches
- 算法竞赛入门经典 第二版 习题4-4 骰子涂色 Cube painting uva253
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 例题+习题(15/16)
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 追踪电子表格中的单元格Uva512
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 特别困的学生 (特困生)
- 算法竞赛入门经典——骰子上色
- 算法竞赛入门经典(第2版)习题4-4 骰子涂色UVa253
- 算法竞赛入门经典(第2版)习题4-4 骰子涂色 Uva253
- IOS获取系统通讯录联系人信息
- #ifdef DEBUG的理解
- ListView嵌套GridView问题
- html Frame、Iframe、Frameset 的区别
- Linux-C 聊天程序学习(socket+pthread)
- 算法竞赛入门经典(第二版)-刘汝佳-第四章 函数与递归 骰子上色Uva253
- 任意文件下载
- 在CentOS7.0上安装Oracle11或12
- Linux常用命令
- HDU 5764 After a Sleepless Night
- Effective C++_Item3笔记
- [刷题]算法竞赛入门经典(第2版) 4-2/UVa201 - Squares
- 理解v4包下ViewPager类的用法
- 死锁的产生和预防死锁