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. 很简单的一个题,只要比较三个对面是否相等就可以了,只要三个对面相等,怎么安排都是一样的六面体。

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

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. const int maxn = 20;
  4. char ch[maxn];
  5. int main()
  6. {
  7. while(scanf("%s",ch+1) != EOF)
  8. {
  9. bool flag = false;
  10. for(int i=1;i<=6;i++)
  11. {
  12. int k;
  13. if(i == 1)
  14. k = 6;
  15. else if(i == 2)
  16. k = 5;
  17. else if(i == 3)
  18. k = 4;
  19. else if(i == 4)
  20. k = 3;
  21. else if(i == 5)
  22. k = 2;
  23. else if(i == 6)
  24. k = 1;
  25. if(ch[i] == 'A')
  26. continue;
  27. char now1,now2;
  28. now1 = ch[i];
  29. now2 = ch[k];
  30. ch[i] = 'A',ch[k] = 'A';
  31. flag = false;
  32. for(int j=7;j<=12;j++)
  33. {
  34. if(ch[j] == now1)
  35. {
  36. if(j == 7 && now2 == ch[12])
  37. {
  38. ch[7] = ch[12] = 'A';
  39. flag = true;
  40. }
  41. else if(j == 8 && now2 == ch[11])
  42. {
  43. flag = true;
  44. ch[8] = ch[11] = 'A';
  45. }
  46. else if(j == 9 && now2 == ch[10])
  47. {
  48. flag = true;
  49. ch[9] = ch[10] = 'A';
  50. }
  51. else if(j == 10 && now2 == ch[9])
  52. {
  53. flag = true;
  54. ch[10] = ch[9] = 'A';
  55. }
  56. else if(j == 11 && now2 == ch[8])
  57. {
  58. flag = true;
  59. ch[8] = ch[11] = 'A';
  60. }
  61. else if(j == 12 && now2 == ch[7])
  62. {
  63. flag = true;
  64. ch[7] = ch[12] = 'A';
  65. }
  66. }
  67. if(flag)
  68. break;
  69. }
  70. if(!flag)
  71. {
  72. printf("FALSE\n");
  73. break;
  74. }
  75. }
  76. if(!flag)
  77. continue;
  78. else
  79. printf("TRUE\n");
  80. }
  81. return 0;
  82. }

水题: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. 使用高性能Pipelines构建.NET通讯程序

    .NET Standard支持一组新的API,System.Span, System.Memory,还有System.IO.Pipelines.这几个新的API极大了提升了.NET程序的效能,将来.N ...

  2. python学习之队列

    import queue task_queue = queue.Queue() #创建队列

  3. vue.js2.0实战填坑记录

    访https://github.com/bailicangdu/vue2-elm的PC商城 在创建的 router 对象中,如果不配置 mode,就会使用默认的 hash 模式,该模式下会将路径格式化 ...

  4. 【转】onAttachedToWindow()在整个Activity生命周期的位置及使用

    上篇博客实现圆角对话框样式的Activity中提到,若需实现圆角对话框Activity,需要在Activity的onAttachedToWindow()函数中做文章,那么就想问: onAttached ...

  5. Java——HashSet和TreeSet的区别

    HashSetHashSet有以下特点 不能保证元素的排列顺序,顺序有可能发生变化 不是同步的 集合元素可以是null,但只能放入一个null当向HashSet集合中存入一个元素时,HashSe ...

  6. Vue-router 的练习

    使用了vue-cli 生成了一套webpack的模版. 之后在其中练习 vue-router. 以下是一些记录. 1.动态路由的配置 import Vue from 'vue' import Rout ...

  7. jquery中ajax请求后台数据成功后既不执行success也不执行error解决方法

    jquery中ajax请求后台数据成功后既不执行success也不执行error,此外系统报错:Uncaught SyntaxError: Unexpected identifier at Objec ...

  8. Sublime Text 3 使用小记

    快捷键: [ // 代码对齐插件 { "keys": ["shift+alt+a"], "command": "alignment ...

  9. svn亲笔操作

    1. 创建版本库 [root@iZ28dftuhfaZ db]# svnadmin create /var/svn-repositories/app-api/ . 导入数据到你的版本库[root@iZ ...

  10. 洛谷 P2068 统计和

    题目描述 给定一个长度为n(n<=100000),初始值都为0的序列,x(x<=10000)次的修改某些位置上的数字,每次加上一个数,然后提出y (y<=10000)个问题,求每段区 ...