UVA-253
题意:如样例一样给立方体编号,然后按编号顺序给出对应的字符,共给你两组12个字符,求判断这两个立方体是否相同。
解题思路:一开始因为想到相对面一对字符是固定的,就可以第二个不动,枚举第一个把哪一对做上面下面,侧面可以通过简单循环求侧面环的顺序,拉成直线暴力比较和第二个侧面的序列。一直WA,看别人题解的时候发现了更简单的做法,因为立方体最上方一共就6种情况,可以先把6个序列存下来,然后每次旋转侧面,和第二个比较。旋转的替换顺序可以看题目的图自己推。
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
using namespace std;
const int c[6][6]={{1,2,3,4,5,6},{2,6,3,4,1,5},{6,5,3,4,2,1},{5,1,3,4,6,2},{3,1,2,5,6,4},{4,6,2,5,1,3}};
string s,s1,s2;
bool tag;
int main () {
freopen("xx.in","r",stdin);
while (cin>>s) {
tag=false;
s2=" ";
for (int i = 1; i <= 6; i++)
s2[i]=s[i-1+6];
s=" "+s;
for (int i = 0; i < 6 && !tag; i++) {
s1=" ";
for (int j = 1; j <= 6; j++)
s1[j] = s[c[i][j-1]];
for (int j = 1; j <= 4; j++){
char t;
t = s1[2];
s1[2] = s1[4];
s1[4] = s1[5];
s1[5] = s1[3];
s1[3] = t;
if (s1 == s2){
tag = true;
break;
}
}
}
if (tag) printf("TRUE\n");
else printf("FALSE\n");
}
}