您的位置:首页 > 其它

算典04_习题_04_UVA-253

2017-03-27 14:43 239 查看

骰子涂色

题意

输入两个骰子,判断二者是否等价

题解

枚举旋转即可

固定一个对面,旋转其余的四个面(这样旋转了四次),总共6个面,总共枚举24次即可判断

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
const int maxn = 1e3 + 5;
const int INF = (1<<15)-1;

char s[20], a[20], b[20], tmp[20];
//上前左右后下
int dir[6][6] = { {1,2,3,4,5,6} ,{2,6,3,4,1,5} ,{3,2,6,1,5,4} ,{4,2,1,6,5,3} ,{5,1,3,4,6,2} ,{6,2,4,3,5,1} };

bool solve() {
for(int i = 1; i <= 6; ++i) a[i] = s[i], b[i] = s[i+6];
for(int i = 0; i <= 5; ++i) {
for(int j = 0; j <= 5; ++j) tmp[j+1] = b[dir[i][j]];

for(int d = 0; d < 4; ++d) {
char t = tmp[2]; tmp[2] = tmp[3];
tmp[3] = tmp[5]; tmp[5] = tmp[4];
tmp[4] = t;
if(!strcmp(tmp+1, a+1)) return 1;
}
}
return 0;
}

int main(){
#ifdef _LOCAL
freopen("in.txt", "r", stdin);
#endif // _LOCAL

while(scanf("%s", s+1) != EOF) {
if(solve()) printf("TRUE\n");
else printf("FALSE\n");
}

return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: