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. 利用Common-Fileupload上传文件图片

    一,介绍 common-fileupload是appache的开源组件,基于该组件可以轻松实现文件上传的功能,strust框架的文件上传功能也是基于该组件. 二,使用 1,导入两个jar包:commo ...

  2. Azkaban是什么?(一)

    不多说,直接上干货! http://www.cnblogs.com/zlslch/category/938837.html Azkaban是什么?  Azkaban是一套简单的任务调度服务,整体包括三 ...

  3. 如何理解linux多用户多任务

    Linux 的单用户.多任务: 容易理解. Linux 的多用户.多任务 举个例子,比如LinuxSir.Org 服务器,上面有FTP 用户.系统管理员.web 用户.常规普通用户等.在同一时刻,比如 ...

  4. zTree树插件动态加载

    需求: 由于项目中家谱图数据量超大,而一般加载方式是通过,页面加载时 zTree.init方法进行数据加载,将所有数据一次性加载到页面中.而在项目中家谱级别又非常广而深,成千上万级,因此一次加载,完全 ...

  5. c# 定时器 自动执行

    //下面讲一个打开窗体定时执行按钮的东西 private void Form1_Load(object sender, EventArgs e) { System.Timers.Timer pTime ...

  6. [转]用NPOI操作EXCEL--通过NPOI获得公式的返回值

    本文转自:http://www.cnblogs.com/atao/archive/2009/10/12/1582085.html 前面我们学习了通过NPOI向Excel中设置公式,那么有些读者可能会问 ...

  7. 移动端REM布局模板(阿里高清方案)

    移动端REM布局模板(阿里高清方案),蛮好的,转自: http://www.jianshu.com/p/985d26b40199 . <!DOCTYPE html> <html la ...

  8. Android学习总结(十七) ———— Handler 的使用

    一.基本概念  handler通俗一点讲就是用来在各个线程之间发送数据的处理对象.在任何线程中,只要获得了另一个线程的handler,则可以通过  handler.sendMessage(messag ...

  9. 洛谷 P2947 [USACO09MAR]仰望Look Up

    题目描述 Farmer John's N (1 <= N <= 100,000) cows, conveniently numbered 1..N, are once again stan ...

  10. COGS 1786. 韩信点兵

    ★★★   输入文件:HanXin.in   输出文件:HanXin.out   简单对比时间限制:1 s   内存限制:256 MB [题目描述] 韩信是中国军事思想“谋战”派代表人物,被后人奉为“ ...