UVA 253 Cube painting(思维题)

18 篇文章 0 订阅
4 篇文章 0 订阅

题意:略

解题思路:所有可能全部枚举, 我估计我是解这个题,方法最笨,代码量最长的人,就别参考了,尽情的笑话我吧。

最下面有神方法, 枚举三次此面,和对立面即可。代码简单易懂。

Description

Download as PDF

We have a machine for painting cubes. It is supplied with three different colors: blue, red and green. Each face of the cube gets one of these colors. The cube's faces are numbered as in Figure 1.

picture21

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in tex2html_wrap_inline126 different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. We denote a painted cube by a string of 6 characters, where each character is a br, or g. The tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) from the left gives the color of face i. For example, Figure 2 is a picture of rbgggr and Figure 3 corresponds to rggbgr. Notice that both cubes are painted in the same way: by rotating it around the vertical axis by 90 tex2html_wrap_inline134 , the one changes into the other.

tex2html_wrap138tex2html_wrap140

Input

The input of your program is a textfile that ends with the standard end-of-file marker. Each line is a string of 12 characters. The first 6 characters of this string are the representation of a painted cube, the remaining 6 characters give you the representation of another cube. Your program determines whether these two cubes are painted in the same way, that is, whether by any combination of rotations one can be turned into the other. (Reflections are not allowed.)

Output

The output is a file of boolean. For each line of input, output contains TRUE if the second half can be obtained from the first half by rotation as describes above, FALSE otherwise.

Sample Input

rbgggrrggbgr
rrrbbbrrbbbr
rbgrbgrrrrrg

Sample Output

TRUE
FALSE
FALSE

Memory: 0 KB Time: 0 MS
Language: C++ 4.8.2 Result: Accepted

#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<list>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>

using namespace std;

#define MAX_N 20
const int INF = 0x3f3f3f3f;
char s[MAX_N], str1[MAX_N], str2[MAX_N], s1[MAX_N], s2[MAX_N];


void separate()
{
    for(int i = 0 ; i < 6 ; i++)
    {
        s1[i] = s[i];
        s2[i] = s[i + 6];
    }
}

bool change_right(char str1[], char str2[])
{
    char tmp = str2[3];
    str2[3] = str2[1];
    str2[1] = str2[2];
    str2[2] = str2[4];
    str2[4] = tmp;

    if(strcmp(str1, str2)) return false;
    else return true;
}

bool change_left(char str1[], char str2[])
{
    char tmp = str2[2];
    str2[2] = str2[1];
    str2[1] = str2[3];
    str2[3] = str2[4];
    str2[4] = tmp;

    if(strcmp(str1, str2)) return false;
    else return true;
}

bool change_up(char str1[], char str2[])
{
    char tmp = str2[0];
    str2[0] = str2[1];
    str2[1] = str2[5];
    str2[5] = str2[4];
    str2[4] = tmp;

    if(strcmp(str1, str2)) return false;
    else return true;
}

bool change_down(char str1[], char str2[])
{
    char tmp = str2[5];
    str2[5] = str2[1];
    str2[1] = str2[0];
    str2[0] = str2[4];
    str2[4] = tmp;

    if(strcmp(str1, str2)) return false;
    else return true;
}

bool change_top_left(char str1[], char str2[])
{
    char tmp = str2[2];
    str2[2] = str2[0];
    str2[0] = str2[3];
    str2[3] = str2[5];
    str2[5] = tmp;

    if(strcmp(str1, str2)) return false;
    else return true;

}

bool change_top_right(char str1[], char str2[])
{
    char tmp = str2[3];
    str2[3] = str2[0];
    str2[0] = str2[2];
    str2[2] = str2[5];
    str2[5] = tmp;

    if(strcmp(str1, str2)) return false;
    else return true;

}

bool change_front(char str1[], char str2[])
{
    char tmp1 = str2[4];
    str2[4] = str2[1];
    str2[1] = tmp1;
    char tmp2 = str2[2];
    str2[2] = str2[3];
    str2[3] = tmp2;

    if(strcmp(str1, str2)) return false;
    else return true;
}

bool change_top(char str1[], char str2[])
{
    char tmp1 = str2[5];
    str2[5] = str2[0];
    str2[0] = tmp1;
    char tmp2 = str2[4];
    str2[4] = str2[1];
    str2[1] = tmp2;

    if(strcmp(str1, str2)) return false;
    else return true;
}

int main()
{
//    freopen("253.txt", "w", stdout);
//    freopen("out.txt", "r", stdin);
    while(scanf("%s", s) != EOF)
    {
        separate();
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top(str1, str2))//1
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2))//1
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2))//1
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2))//2
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_up(str1, str2))//3
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_down(str1, str2))//4
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2))//5
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2))//6
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_up(str1, str2)|| change_left(str1, str2))//7
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2)|| change_up(str1, str2))//8
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_up(str1, str2)|| change_right(str1, str2))//9
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2)|| change_up(str1, str2))//10
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_down(str1, str2)|| change_right(str1, str2))//11
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2)|| change_down(str1, str2))//12
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_down(str1, str2)|| change_left(str1, str2))//13
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2)|| change_down(str1, str2))//14
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2)|| change_left(str1, str2))//15
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2)|| change_top_left(str1, str2))//16
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2)|| change_right(str1, str2))//17
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2)|| change_top_left(str1, str2))//18
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2)|| change_up(str1, str2))//19
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_up(str1, str2)|| change_top_right(str1, str2))//20
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2)|| change_down(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_down(str1, str2)|| change_top_right(str1, str2))//22
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_up(str1, str2)|| change_top_left(str1, str2))
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2)|| change_up(str1, str2))
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2)|| change_down(str1, str2))
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_down(str1, str2)|| change_top_left(str1, str2))
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2)|| change_left(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2)|| change_top_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2)|| change_top_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2)|| change_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top(str1, str2)|| change_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2)|| change_top(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2)|| change_top(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top(str1, str2)|| change_left(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_left(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_left(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_right(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_top(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top(str1, str2)|| change_top_left(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2)|| change_top(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top(str1, str2)|| change_top_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2)|| change_top(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_top_right(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_right(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_top_left(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_top_left(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_up(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_up(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_down(str1, str2)|| change_front(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        strcpy(str1, s1);
        strcpy(str2, s2);
        if(change_front(str1, str2)|| change_down(str1, str2))//21
        {
            cout<<"TRUE"<<endl;
            continue;
        }
        cout<<"FALSE"<<endl;
    }

    return 0;
}


Memory: 0 KB Time: 0 MS
Language: C++ 4.8.2 Result: Accepted

#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<list>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>

using namespace std;

/**************************************************************/
#define MAX_N 20
const int INF = 0x3f3f3f3f;
char s[MAX_N], s1[MAX_N], s2[MAX_N];

void separate()
{
    for(int i = 0 ; i < 6 ; i++)
    {
        s1[i] = s[i];
        s2[i] = s[i + 6];
    }
}

int main()
{
    while(~scanf("%s", s))
    {
        separate();
        int ans = 1;
        for(int i = 0 ; i < 3 ; i++)
        {
            int flag = 0;
            for(int j = 0 ; j < 6 ; j++)
            {
                if(s1[i] == s2[j] && s1[5 - i] == s2[5 - j])
                {
                    flag = 1;
                    s2[j] = 'o';
                    s2[5 - j] = 'o';
                    break;
                }
            }
            if(!flag)
            {
                ans = 0;
                break;
            }
        }
        if(ans) cout<<"TRUE"<<endl;
        else cout<<"FALSE"<<endl;
    }

    return 0;
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值