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\n");
break;
}
}
if(!flag)
continue;
else
printf("TRUE\n");
}
return 0;
}

水题:UVa253-Cube painting的更多相关文章

  1. [刷题]算法竞赛入门经典(第2版) 4-4/UVa253 - Cube painting

    书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) #include<iostream> char str[15]; v ...

  2. UVA253 Cube painting(数学)

    题目链接. 分析: 用的<训练指南>上的方法.详见P17. 从6个面中选一个做顶面,再从剩下的4个面中选1个做正面,则此正方体唯一确定. 需要枚举共6*4=24种. #include &l ...

  3. uva253 Cube painting(UVA - 253)

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

  4. HDU5053the Sum of Cube(水题)

    HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...

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

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

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

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

  7. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  8. ACM :漫漫上学路 -DP -水题

    CSU 1772 漫漫上学路 Time Limit: 1000MS   Memory Limit: 131072KB   64bit IO Format: %lld & %llu Submit ...

  9. ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)

    1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 154  Solved: 112[ ...

随机推荐

  1. Mex(线段树的巧妙应用)

    题目要求求某段区间第一个没有出现的数(0,1,2,3....) ,对于所有的区间,我们把这样的数加起来最后得到一个结果. 首先,我们要求出这样的数,然后还得列举出所有的区间,复杂度太大了. 换种思路, ...

  2. docker镜像与容器

    目录 docker镜像与容器 概述 分层存储 镜像与容器 删除镜像与容器 将容器中的改动提交到镜像 慎用 docker commit--构建镜像推荐使用dockerfile docker镜像与容器 概 ...

  3. ubuntu 下 docker安装

    1移除以前安装docker sudo apt-get remove docker docker-engine docker-ce docker.io 2 安装包以允许apt通过HTTPS使用存储库 s ...

  4. Eclipse中一直出现 Android SDK resolving error markers

    Eclipse中一直出现“Android SDK: resolving error markers”. 此类情况网上有诸多描述以及相应尝试性的解决方法,不久前本人即出现此类情况,尝试多种方案后未能解决 ...

  5. java 设计模式 之 桥梁模式

    桥梁模式:将抽象和实现解耦,使两者可以独立的变化.解释:将两个有组合关系,强耦合的对象,各自抽象然后解耦.(类关系图看https://www.cnblogs.com/blogxiao/p/951388 ...

  6. azure 创建redhat镜像帮助

    为 Azure 准备基于 Red Hat 的虚拟机 从 Hyper-V 管理器准备基于 Red Hat 的虚拟机 先决条件 本部分假定你已经从 Red Hat 网站获取 ISO 文件并将 RHEL 映 ...

  7. moment.js获取当前日期是当年的第几周

    /** * 实现当前日期是当年的第几周,再向前和向后推几周 * js数组保存当前日期的前后两周(共五周的数据) * */ var initSearchMajorChanges = function() ...

  8. 一个具体的例子学习Java volatile关键字

    相信大多数Java程序员都学习过volatile这个关键字的用法.百度百科上对volatile的定义: volatile是一个类型修饰符(type specifier),被设计用来修饰被不同线程访问和 ...

  9. Python 元组、字典、集合操作总结

    元组 a=('a',) a=('a','b') 特点 有序 不可变,不可以修改元组的值,无法为元组增加或者删除元素 元组的创建 a=('a',) a=('a','b') tuple('abcd') 转 ...

  10. Higher level thinking

    「Higher level thinking」-- 出自 Ray Dalio 的<Principles>(PDF 原文:Principles by Ray Dalio) Higher le ...