UVA - 253 Cube painting
2016-07-15 21:08
429 查看
题目大意:给两个正方体涂色,问经过旋转是否能变为一模一样。
解题思路:检测两个正方体的三对面颜色是否对应相等,相等令其为 0,有三对之后输出 TRUE。
解题思路:检测两个正方体的三对面颜色是否对应相等,相等令其为 0,有三对之后输出 TRUE。
#include<iostream> #include<cstdio> #include<string.h> #include<stdlib.h> #include<cmath> using namespace std; char s[15]; char cube[2][6]; char tmp[2][6]; bool same(int i,int j) { if(cube[0][i] == cube[1][j] && cube[0][5-i] == cube[1][5-j]) { cube[0][i] = cube[1][j] = cube[0][5-i] = cube[1][5-j] = '0'; return true; } if(cube[0][i] == cube[1][5-j] && cube[0][5-i] == cube[1][j]) { cube[0][i] = cube[1][5-j] = cube[0][5-i] = cube[1][j] = '0'; return true; } return false; } int main() { while(scanf("%s", s) != EOF) { int tag = 0; for (int i = 0; i < 2; i++) for (int j = 0; j < 6; j++) tmp[i][j] = s[tag++]; while(1) { tag = 0; strcpy(cube[0], tmp[0]); strcpy(cube[1], tmp[1]); int i, j; for(i = 0; i < 3; i++) for(j = 0; j < 3; j++) if(cube[0][i] != '0' && cube[1][j] != '0' && same(i, j)) tag++; if (tag == 3) { tag = 1; break;} else if (i == 3) { tag = 0; break;} } printf(tag?"TRUE\n":"FALSE\n"); } return 0; }
相关文章推荐
- 1.10055 - Hashmat the brave warrior
- 2.10071 - Back to High School Physics
- 3.458 - The Decoder
- 4.694 - The Collatz Sequence
- 6.494 - Kindergarten Counting Game
- 7.490 - Rotating Sentences
- 8.414 - Machined Surfaces
- 9.488 - Triangle Wave
- A.457 - Linear Cellular Automata
- B.489 - Hangman Judge
- C.445 - Marvelous Mazes
- 1.10494 - If We Were a Child Again
- 2.424 - Integer Inquiry
- 3.10250 - The Other Two Trees
- 5.465 - Overflow
- 6.113 - Power of Cryptography
- 7.10161 - Ant on a Chessboard
- 8.621 - Secret Research
- 9.401 - Palindromes
- A.537 - Artificial Intelligence?