UVa 253 Cube painting (模拟)
2013-09-14 14:27
399 查看
253 - Cube painting
Time limit: 3.000 secondshttp://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=99&page=show_problem&problem=189
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, org. 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 remaining6 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
枚举每个对面,再旋转比较剩下4个面,注意顺序。
完整代码:
#include <iostream> using namespace std; char str[15]; int judge(int a, int b, int c, int d, int e, int f) { if (str[a] == str[0] && str[b] == str[5]) { if (str[1] == str[c] && str[3] == str[d] && str[4] == str[e] && str[2] == str[f]) return true; if (str[1] == str[d] && str[3] == str[e] && str[4] == str[f] && str[2] == str[c]) return true; if (str[1] == str[e] && str[3] == str[f] && str[4] == str[c] && str[2] == str[d]) return true; if (str[1] == str[f] && str[3] == str[c] && str[4] == str[d] && str[2] == str[e]) return true; return false; } return false; } int main() { while (cin >> str) { if (judge(6, 11, 7, 9, 10, 8) ||judge(11, 6, 10, 9, 7, 8) ||judge(7, 10, 11, 9, 6, 8) ||judge(10, 7, 6, 9, 11, 8) ||judge(8, 9, 11, 7, 6, 10) ||judge(9, 8, 6, 7, 11, 10)) cout << "TRUE" << endl; else cout << "FALSE" << endl; } }
相关文章推荐
- 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(p97)----Cube painting
- 20160324 codevs 2956 排队问题,poj Ancient Cipher,uva 253 - Cube painting
- UVA253-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-AC
- UVA - 253 Cube painting
- UVA 253 Cube painting
- UVA-253 Cube painting