算典04_习题_04_UVA-253

骰子涂色

题意

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

题解

枚举旋转即可
固定一个对面,旋转其余的四个面(这样旋转了四次),总共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;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值