Cube painting

Problem Description:

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 tex2html_wrap_inline126 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 tex2html_wrap_inline128 character ( tex2html_wrap_inline130 ) 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 tex2html_wrap_inline134 , 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

这题我看了后觉得还算简单,就开始写了,我用的是找规律,然而发现不对,之后觉得要打表,因为没有规律。最后还有一个坑,就是比如1放底下,6放上面和6放底下,1放上面是不一样的,还有把表swap一下,也就是我的table2。写完直到a了,用了3,4个小时。。。- -

【题目链接】UVA 253 Cube painting

【题目类型】打表

&题意:

有一个正方体方块,6个面可以有不同的字母,但你必须按照题目中说的顺序去读它,先给你一个一个串s1,问你是否能用s1的方块任意变换,使他变成s2,也就是说s1和s2是否是同一个方块。

&题解:

这个我刚看完的话,大致想了下,有2*4*3种情况,2是2种不同的底,4是4个方向,3是3种情况,分别是1, 6和 4, 3和 5, 2。

那么比如就以1为底,6为顶,分别去找那4种情况,也就是变换的4种角度,打表(不要以为这有规律,就老实的打表吧,或许也有但我没发现),以下同理就好。不要忘了换了底之后swap表一下

【时间复杂度】O(24*n) n是输入的组数,因为共有24种情况

&代码:

#include <bits/stdc++.h>
using namespace std;
string s1, s2, s[50];
int ct;
bool fl = 0;
int g[3][2] = {1, 6, 4, 3, 5, 2};
int tt[3][4] = {2, 3, 4, 5, 1, 2, 5, 6, 1, 3, 4, 6};
int table[3][16] = {
2, 3, 4, 5, 4, 2, 5, 3, 5, 4, 3, 2, 3, 5, 2, 4,
2, 1, 6, 5, 1, 5, 2, 6, 5, 6, 1, 2, 6, 2, 5, 1,
1, 3, 4, 6, 3, 6, 1, 4, 6, 4, 3, 1, 4, 1, 6, 3
};
int table2[3][16];
void excha(int a) {
for (int i = 0; i < 4; i++) {
s[ct] = s1;
s[ct][0] = s1[g[a][0] - 1];
s[ct][5] = s1[g[a][1] - 1];
int t = 1;
for (int j = 0; j < 4; j++) {
s[ct][t++] = s1[table[a][i * 4 + j] - 1];
}
ct++;
}
for (int i = 0; i < 4; i++) {
s[ct] = s1;
s[ct][5] = s1[g[a][0] - 1];
s[ct][0] = s1[g[a][1] - 1];
int t = 1;
for (int j = 0; j < 4; j++) {
s[ct][t++] = s1[table2[a][i * 4 + j] - 1];
}
ct++;
}
}
void Solve() {
for (int i = 0; i < 3; i++)
for (int j = 0; j < 16; j += 2)
table2[i][j] = table[i][j + 1], table2[i][j + 1] = table[i][j];
while (cin >> s1) {
fl = 0;
ct = 0;
s2 = s1.substr(6);
s1.resize(6);
for (int i = 0; i < 3; i++)
excha(i);
// for (int i = 0; i < ct; i++)
// PI(s[i])
for (int i = 0; i < ct; i++)
if (s[i] == s2) fl = 1;
if (fl) puts("TRUE");
else puts("FALSE");
}
}
int main() {
Solve();
return 0;
}

UVA 253 Cube painting(暴力打表)的更多相关文章

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

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

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

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

  3. UVA 253 Cube painting

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

  4. UVa 253 Cube paiting

    题意:输入两个骰子,判断是否等价 因为每一个面可以作顶面,共6*4种情况,枚举就可以了 #include<iostream> #include<cstdio> #include ...

  5. UVA.12716 GCD XOR (暴力枚举 数论GCD)

    UVA.12716 GCD XOR (暴力枚举 数论GCD) 题意分析 题意比较简单,求[1,n]范围内的整数队a,b(a<=b)的个数,使得 gcd(a,b) = a XOR b. 前置技能 ...

  6. ACM/ICPC 之 暴力打表(求解欧拉回路)-编码(POJ1780)

    ///找到一个数字序列包含所有n位数(连续)一次且仅一次 ///暴力打表 ///Time:141Ms Memory:2260K #include<iostream> #include< ...

  7. UVA 253 (13.08.06)

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

  8. XTU OJ 1210 Happy Number (暴力+打表)

    Problem Description Recently, Mr. Xie learn the concept of happy number. A happy number is a number ...

  9. 【ZOJ】3785 What day is that day? ——浅谈KMP在ACM竞赛中的暴力打表找规律中的应用

    转载请声明出处:http://www.cnblogs.com/kevince/p/3887827.html    ——By Kevince 首先声明一下,这里的规律指的是循环,即找到最小循环周期. 这 ...

随机推荐

  1. hdu3342 拓扑序

    题意:一个QQ群里面有一群大神,他们互相帮助解决问题,然后互相膜拜,于是有些人就称别人是他师父,现在给出很多师徒关系,问是否有矛盾 拓扑序,按师徒关系建边直接拓扑序就行了. #include<s ...

  2. 英语语法最终珍藏版笔记- 21it 用法小结

    it 用法小结 it 在英语中的意思较多,用法较广,现总结如下. 一.it作句子的真正主语 1.it 指前面已经提到过的人或事物,有时指心目中的或成为问题的人或事物,作真正主语. 例如: What’s ...

  3. C# App.config 自定义 配置节 报错“配置系统未能初始化” 解决方法

    App.config,结果运行的时候出现了 "配置系统未能初始化" 的错误.找了半天才发现是下面的原因造成的: "如果配置文件中包含configSections元素,则c ...

  4. kuangbin_ShortPath R (HDU 4370)

    出题人真是脑洞堪比黑洞 (然后自己也被吸进去了 理解一遍题意 三个条件可以转化为 1的出度是1, n的入度是1, 2~n-1的出度等于入度 不难发现1-n的最短路符合题意 然而其实还有另一种情况 1为 ...

  5. kuangbin_ShortPath A (POJ 2387)

    最短路模板题 但是其实很费时间 因为要看明白dij floyd 以及 dij优化 spfa优化 交了三次 大概是理解了 不过涉及到priority_queue的重载运算符问题 以后要在C++里面好好看 ...

  6. 修改host文件屏蔽视频广告和网站

    很多时候我们会需要屏蔽一些网站或者广告,类似XX网站,下木马病毒的网站,或者破解软件的时候.我们可以使用一些软件屏蔽,我这里是用windows系统自带的hosts文件来屏蔽的.这个文件有点类似精简版的 ...

  7. 另一个分区工具GNU的parted[转自vbird]

    利用 GNU 的 parted 进行分割行为 虽然你可以使用 fdisk 很快速的将你的分割槽切割妥当,不过 fdisk 却无法支持到高于 2TB 以上的分割槽! 此时就得需要 parted 来处理了 ...

  8. Memory Barriers ,cache-coherency

    http://www.rdrop.com/users/paulmck/scalability/paper/whymb.2010.07.23a.pdf Shared-Memory Synchroniza ...

  9. lucene 检索流程整理笔记

  10. 使用JavaScript实现一个倒数计时程序

    使用JavaScript在网页中实现一个计算当年还剩多少时间的倒数计时程序,网页上能够实时动态显示“XX年还剩XX天XX时XX分XX秒”: 程序代码如下: <meta charset=" ...