题目链接如下:
这个解法是参考题解 UVA253 【Cube painting】 - FP·荷兰猪 的博客 - 洛谷博客 写的,这应该是符合逻辑的解法。最外面的循环是代表分别以不同位置为顶,内部循环是水平旋转四次,看得到的结果。代码如下:
- #include
- #include
- // #define debug
-
- std::string str, s, t;
- int dir[6][6] = {{0, 1, 2, 3, 4, 5}, {1, 5, 2, 3, 0, 4}, {2, 1, 5, 0, 4, 3},
- {3, 1, 0, 5, 4, 2}, {4, 3, 0, 5, 2, 1}, {5, 1, 3, 2, 4, 0}};
-
- bool judge(std::string a, std::string b){
- for(int i = 0; i < 6; ++i){
- std::string mp;
- for(int j = 0; j < 6; ++j){
- mp.push_back(a[dir[i][j]]);
- }
- for(int j = 0; j < 4; ++j){
- char c = mp[2];
- mp[2] = mp[4];
- mp[4] = mp[3];
- mp[3] = mp[1];
- mp[1] = c;
- if(mp == b){
- return true;
- }
- }
- }
- return false;
- }
-
- int main(){
- #ifdef debug
- freopen("0.txt", "r", stdin);
- freopen("1.txt", "w", stdout);
- #endif
- while(std::cin >> str){
- s = str.substr(0, 6);
- t = str.substr(6);
- printf("%s\n", judge(s, t) ? "TRUE" : "FALSE");
- }
- #ifdef debug
- fclose(stdin);
- fclose(stdout);
- #endif
- return 0;
- }
下面这个代码是我写的,能AC,但我觉得逻辑不对,是乱拳打死老师傅AC的……今天脑子昏昏沉沉的,等我脑子好使一些再来检查。
代码如下:
- #include
- #include
-
- std::string str, s, t;
-
- void rotate1(std::string &a){
- std::string b = a;
- a[0] = b[1];
- a[1] = b[5];
- a[4] = b[0];
- a[5] = b[4];
- }
-
- void rotate2(std::string &a){
- std::string b = a;
- a[1] = b[2];
- a[2] = b[4];
- a[3] = b[1];
- a[4] = b[3];
- }
-
- void rotate3(std::string &a){
- std::string b = a;
- a[0] = b[2];
- a[2] = b[5];
- a[3] = b[0];
- a[5] = b[3];
- }
-
- bool judge(std::string a, std::string b){
- for(int i = 0; i <= 3; ++i){
- rotate1(a);
- for(int j = 0; j <= 3; ++j){
- rotate2(a);
- for(int k = 0; k <= 3; ++k){
- rotate3(a);
- if(a == b){
- return true;
- }
- }
- }
- }
- return false;
- }
-
- int main(){
- while(std::cin >> str){
- s = str.substr(0, 6);
- t = str.substr(6);
- printf("%s\n", judge(s, t) ? "TRUE" : "FALSE");
- }
- return 0;
- }