UVa 253 Cube painting

本文介绍了一种通过旋转六面体以使两个给定的面序列相匹配的算法实现。该算法首先固定其中一个面作为前后面,然后尝试通过旋转来匹配另一组面序列。通过多次旋转和比较,判断两组面序列是否可以通过旋转达到相同状态。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

思路 模拟每个面在前面的情况  固定前后时,以前后 为轴旋转  

参考:https://blog.youkuaiyun.com/ramay7/article/details/50357366

https://blog.youkuaiyun.com/shiqi_614/article/details/7035558

AC代码:

#include <iostream>
    #include <cstdio>
    #include <cstring>
    using namespace std;
    const int N=20;
    char str[N],str1[N],str2[N];
    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,0,2,3,5,1},{5,4,2,3,1,0} };

                    bool fun()
    {
        char temp[N]={0};
        for(int i=0;i<6;i++)
        {
            for(int j=0;j<6;j++)
            {
                temp[j]=str1[dir[i][j]];
            }
            for(int j=0;j<4;j++)
            {
                char c;
                c=temp[1];
                temp[1]=temp[2];
                temp[2]=temp[4];
                temp[4]=temp[3];
                temp[3]=c;
                if(strcmp(temp,str2)==0) return 1;
            }
        }
        return 0;
    }
    int main()
    {
        while(scanf("%s",str)!=EOF)
        {
            for(int i=0;i<6;i++) {str1[i]=str[i];str2[i]=str[i+6];}

            if(fun()) printf("TRUE\n");
            else printf("FALSE\n");
        }
        return 0;
    }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值