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.

 We denote a painted cube by a string of 6 characters, where each 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 Figure 1 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

HINT

   暴力AC是真的爽啊!!!一开始的想法是将一个正方形分成3个环形的面,然后以一个为标准另一个正方体的面为对照,一共有3!=6种组合方式。自我感觉是没有啥毛病的,但是从udebug上的数据发现了好几个错误,修改了半天一直修不好。然后果断放弃幻想直接暴力。

暴力方法:

  无论一个正方体怎么旋转6个面还是6个面,将所有的6个面的一种情况列出来,然后上底面和下底面固定时又对应四种情况再次列举出来。直接利用循环判断每一种情况,暴力解决。

Accepted

#include<stdio.h>
#include<stdlib.h>
#include<string.h> //6个面分别位于上底面时的其中一种情况
int arr[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,5,3,4,2,1} };
//上底面和下地面固定对应的4种情况
int arr1[4][6] = { {1,2,3,4,5,6},{1,3,5,2,4,6},{1,4,2,5,3,6},{1,5,4,3,2,6} }; void translate(char* temp, char* s, int* arr2)
{
for (int i = 0;i < 6;i++)
temp[i] = s[arr2[i] - 1];
} int main()
{
char s[13];
while (scanf("%s", s) != EOF)
{
char s1[7] = { 0 };
char s2[7] = { 0 };
strncpy(s1, s, 6); //将两个立方体区分开来
strncpy(s2, s+6, 6);
int flag = 0;
for (int i = 0;i < 6;i++)
{
char temp[7] = { 0 };
char temp1[7] = { 0 };
translate(temp, s1, arr[i]);//先找到一种情况
for (int j = 0;j < 4;j++)
{
translate(temp1, temp, arr1[j]);//判断着一种情况对应的4个状态
if (strncmp(temp1, s2, 6) == 0)
{
flag = 1;
break;
}
}
if (flag)break;
}
printf("%s\n", flag == 1 ? "TRUE" : "FALSE");
}
}

Cube painting UVA - 253的更多相关文章

  1. 骰子涂色 (Cube painting,UVa 253)

    题目描述:算法竞赛入门习题4-4  题目思路:1.旋转其中一个骰子进行匹配 2.进行遍历,如果匹配,就进行相对面的匹配 3.三个对立面都匹配即是一样等价的 //没有按照原题的输入输出 #include ...

  2. uva253 Cube painting(UVA - 253)

    题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相 ...

  3. uva 253 - Cube painting(相同骰子)

    习题4-4 骰子涂色(Cube painting, UVa 253) 输入两个骰子,判断二者是否等价.每个骰子用6个字母表示,如图4-7所示. 图4-7 骰子涂色 例如rbgggr和rggbgr分别表 ...

  4. UVA 253 Cube painting(暴力打表)

    Cube painting Problem Description: We have a machine for painting cubes. It is supplied with three d ...

  5. UVA 253 (13.08.06)

     Cube painting  We have a machine for painting cubes. It is supplied withthree different colors: blu ...

  6. UVa 253

    UVa 253 #include <iostream> #include <cstdio> #include <string> #include <cstri ...

  7. UVA 253 Cube painting

    大致题意:有三种颜色,一个立方体6面都可以涂一种颜色.现在给出两个每个面都涂好颜色的立方体,判断这两个立方体通过旋转是否相等. 立方体的旋转出来的结果有很多,首先可以0,1,2,3,4,5(顺序是:上 ...

  8. UVA 253 Cube painting(枚举 模拟)

    题意: 按如图的顺序给定2个骰子的颜色(只有r.b.g三种颜色) 问2个骰子是否一模一样 如 可表示为“rbgggr” 和 “rggbgr”, 第二个就是绕着Z轴顺时针旋转90度与第一个相同的骰子. ...

  9. 【习题 4-4 UVA - 253】Cube painting

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 绕(x,y,z)三个轴旋转. 枚举x,y,z各4次的结果. (4次之后能还原.可以方便上一层枚举下一个情况.) [代码] #incl ...

随机推荐

  1. Dev GridControl列绑定LookUpEdit数据源:默认值

    在Winform开发过程中,GridControl控件是比较常见的,尤其是其数据源的灵活性,为我们提供了不少的便利. 在使用Dev的GridControl的时候,有时候会在列的Column Edit属 ...

  2. 两个"�"="锟斤拷"?

    关于作者:程序猿石头(ID: tangleithu),现任阿里巴巴技术专家,清华学渣,前大疆后端 Leader.欢迎关注,交流和指导! 本文首发于微信公众号,原文链接,转载请全文保留. 以一首七言绝句 ...

  3. 微信小程序:上滑触底加载下一页

    给商品列表页面添加一个上滑触底加载下一页的效果,滚动条触底之后就发送一个请求,来加载下一页数据, 先在getGoodsList中获取总条数 由于总页数需要再另外的一个方法中使用,所以要把总页数变成一个 ...

  4. 前端问题录——在导入模块时使用'@'时提示"Modile is not installed"

    前情提要 为了尽可能解决引用其他模块时路径过长的问题,通常会在 vue.config.js 文件中为 src 目录配置一个别名 '@' configureWebpack: { resolve: { a ...

  5. 生产者与消费者以及ActiveMQ

    生产者与消费者以及ActiveMQ 一. 多线程实现生产者与消费者 1.1 生产者与消费者头文件 #pragma once #include <iostream> #include < ...

  6. 后端程序员之路 17、LaTeX公式

    之前的文章写了两个公式:d(x,y)=\sqrt{\sum_{i=1}^{n}(x_i-y_i)^2} H_x=-\sum_{i=1}^{n}p(x_i)\log_{2}{p(x_i)} LaTex ...

  7. 全局解决Vue跳转相同路由导致报错的问题

    大家使用Vue做开发的时候应该都遇到过这个问题,就是某个页面下调用this.$router.push(path),而path指向的页面和当前页面是同一页面时,就会发生报错,vue-router会提示你 ...

  8. InterJ idea 回滚提交的代码

    如果你要回滚到这一次提交 ctrl shift k 提交 选force push 那么你的代码就回滚到你所想要的这次提交记录了

  9. 翻译:《实用的Python编程》04_03_Special_methods

    目录 | 上一节 (4.2 继承) | 下一节 (4.4 异常) 4.3 特殊方法 可以通过特殊方法(或者称为"魔术"方法(magic method))自定义 Python 行为的 ...

  10. NewSQL分布式数据库,例如TIDB用K/V的底层逻辑

    内容参考 对分布式对定义参考这篇文章: 微服务都想用,先把分布式和微服务之间的关系说清楚 对分布式架构中心或无中心对比参考这篇文章: 分布式存储单主.多主和无中心架构的特征与趋势 对HDFS对内部机制 ...