zoukankan      html  css  js  c++  java
  • 水题:UVa253-Cube painting

    Cube painting

    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. Since a cube has 6 faces, our machine can paint a face-numbered cube in 36 = 729 different ways. When ignoring the face-numbers, the number of different paintings is much less, because a cube can be rotated. See example below. Wedenoteapaintedcubebyastringof6characters, whereeach character is a ‘b’, ‘r’, or ‘g’. The i-th character (1 ≤ i ≤ 6) 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°, the one changes into the other.

    这里写图片描述这里写图片描述
    这里写图片描述

    Input

    The input of your program is a text file 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


    解题心得:

    1. 很简单的一个题,只要比较三个对面是否相等就可以了,只要三个对面相等,怎么安排都是一样的六面体。

    反正都这么简单,代码就瞎写的

    #include<bits/stdc++.h>
    using namespace std;
    const int maxn = 20;
    char ch[maxn];
    int main()
    {
        while(scanf("%s",ch+1) != EOF)
        {
            bool flag = false;
            for(int i=1;i<=6;i++)
            {
                int k;
                if(i == 1)
                    k = 6;
                else if(i == 2)
                    k = 5;
                else if(i == 3)
                    k = 4;
                else if(i == 4)
                    k = 3;
                else if(i == 5)
                    k = 2;
                else if(i == 6)
                    k = 1;
                if(ch[i] == 'A')
                    continue;
                char now1,now2;
                now1 = ch[i];
                now2 = ch[k];
                ch[i] = 'A',ch[k] = 'A';
                flag = false;
                for(int j=7;j<=12;j++)
                {
    
                    if(ch[j] == now1)
                    {
                        if(j == 7 && now2 == ch[12])
                        {
                            ch[7] = ch[12] = 'A';
                            flag = true;
                        }
                        else if(j == 8 && now2 == ch[11])
                        {
                            flag = true;
                            ch[8] = ch[11] = 'A';
                        }
                        else if(j == 9 && now2 == ch[10])
                        {
                            flag = true;
                            ch[9] = ch[10] = 'A';
                        }
                        else if(j == 10 && now2 == ch[9])
                        {
                            flag = true;
                            ch[10] = ch[9] = 'A';
                        }
                        else if(j == 11 && now2 == ch[8])
                        {
                            flag = true;
                            ch[8] = ch[11] = 'A';
                        }
                        else if(j == 12 && now2 == ch[7])
                        {
                            flag = true;
                            ch[7] = ch[12] = 'A';
                        }
                    }
                    if(flag)
                        break;
                }
                if(!flag)
                {
                    printf("FALSE
    ");
                    break;
                }
            }
            if(!flag)
                continue;
            else
                printf("TRUE
    ");
        }
        return 0;
    }
    
  • 相关阅读:
    SSH 远程执行任务
    C# 创建压缩文件
    迁移 SQL Server 到 Azure SQL 实战
    在 Azure 上部署 Asp.NET Core Web App
    linux kill 命令
    VS 远程调试 Azure Web App
    Azure 基础:自定义 Table storage 查询条件
    NSOperation的使用细节 [2]
    NSOperation的使用细节 [1]
    [翻译] SSKeychain
  • 原文地址:https://www.cnblogs.com/GoldenFingers/p/9107271.html
Copyright © 2011-2022 走看看