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.

Figure 1.

Since a cube has 6 faces, our machine can paint a face-numbered cube in  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, org. The  character (  ) 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 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

这个方法是参考大神的,实在是不能太6.
#include <cstdio>
#include <cstring>

char str[15];
int vis[3];        /*每两个对面形成一组颜色对, 每个正方体有三个颜色对,
                匹配下三个颜色对是否相同。(用vis标记检查顺序)*/

int main()
{
    while(scanf("%s", str) != EOF)
    {
        int cnt = 0;
        memset(vis, 0, sizeof(vis));
        for(int i = 0; i < 3; i++)
        {
            for(int j = 0; j < 3; j++)
            {
                if((str[i] == str[6+j] && str[5-i] == str[11-j]) || (str[i] == str[11-j] && str[5-i] == str[6+j]) && !vis[j])
                {
                    vis[j] = 1;
                    cnt++;
                    break;
                }
            }
        }
        if(cnt == 3) printf("TRUE\n");
        else printf("FALSE\n");
    }
}
时间: 2024-10-11 20:33:43

UVA253-Cube painting的相关文章

UVA253 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

uva253 Cube painting(UVA - 253)

题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相同的面并且他们的对面相等那么继续寻找,直到三个面都能找到相对立的面 ③如果有一个面没有找到相等的面或者相等的对面之类的那么就break循环然后直接判断FALSE如果三个面都能满足上述条件,那么就是TRUE 代码 #include <bits/stdc++.h> using namespace st

Cube painting UVA 253

说说:一看到给立方体染色,开始还有点小害怕.毕竟高中数学里染色问题从来都不会简单.这道题的意思就是给立方体的六个面染色,然后判断两个染了色的立方体是否一样.其实仔细一想,立方体无非三对面,若开始确定两对面.如下面图Figure 1所示:假设1,2,6,5这四个面先确定(这只有唯一一种情况)之后,再放3,4,的时候无非两种情况.但这两种情况是不一样的,这也许就是题目所说的reflection.开始的想法是找出三对面,然后比较是否相等即可,不过实在想不出怎样来排除reflection的情况.所以只能

uva 253 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. Figure 1. Since a cube has 6 faces, o

uva 253 - Cube painting(相同骰子)

习题4-4 骰子涂色(Cube painting, UVa 253) 输入两个骰子,判断二者是否等价.每个骰子用6个字母表示,如图4-7所示. 图4-7 骰子涂色 例如rbgggr和rggbgr分别表示如图4-8所示的两个骰子.二者是等价的,因为图4-8(a) 所示的骰子沿着竖直轴旋转90°之后就可以得到图4-8(b)所示的骰子. (a) (b) 图4-8 旋转前后的两个骰子 . Sample Input rbgggrrggbgr rrrbbbrrbbbr rbgrbgrrrrrg Sample

UVA 253 Cube painting(枚举 模拟)

题意: 按如图的顺序给定2个骰子的颜色(只有r.b.g三种颜色) 问2个骰子是否一模一样 如 可表示为"rbgggr" 和 "rggbgr", 第二个就是绕着Z轴顺时针旋转90度与第一个相同的骰子. 分析: 记录一个错误的做法:并不是只要两面两面互相映射, 如rbrggb 与 rgrgbb, 即使 rb 对应 rb.gb 对应 bg. rg对应rg, 但他们并不是一模一样的骰子.(可以借助真正的骰子旋转尝试一下,就是123456 和 153426, 想象一下2与5互

算法竞赛入门经典 第四章

[√ ] UVA1339 古老的密码 Ancient Cipher [√ ] UVA489 刽子手的游戏 Hangman Judge [√ ] UVA133 救济金发放 The Dole Queue [√ ] UVA213 信息解码 Message Decoding [√ ] UVA512 追踪电子表格中的单元格 Spreadsheet Tracking [√ ] UVA12412 师兄帮帮忙 A Typical Homework (a.k.a Shi Xiong Bang Bang Mang)

UVA题目分类

题目 Volume 0. Getting Started 开始10055 - Hashmat the Brave Warrior 10071 - Back to High School Physics 10300 - Ecological Premium 458 - The Decoder 494 - Kindergarten Counting Game 414 - Machined Surfaces 490 - Rotating Sentences 445 - Marvelous Mazes

UVa253

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. Figure 1. Since a cube has 6 faces, our machine can p