博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UVA 253 Cube painting(暴力打表)
阅读量:4571 次
发布时间:2019-06-08

本文共 3605 字,大约阅读时间需要 12 分钟。

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个小时。。。- -

【题目链接】

【题目类型】打表

&题意:

有一个正方体方块,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 
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;}

转载于:https://www.cnblogs.com/s1124yy/p/5844041.html

你可能感兴趣的文章
doubleclick adx note
查看>>
Celery框架
查看>>
[c#]asp.net开发微信公众平台(4)关注事件、用户记录、回复文本消息
查看>>
[转载,感觉写的非常详细]DUBBO配置方式详解
查看>>
Android在Eclipse上的环境配置
查看>>
面向对象(五)
查看>>
android平台下使用点九PNG技术
查看>>
Python学习3,列表
查看>>
最长回文子串
查看>>
JAVA基础-JDBC(一)
查看>>
js中for和while运行速度比较
查看>>
算法第5章作业
查看>>
7.9 练习
查看>>
基于ArcGIS JS API的在线专题地图实现
查看>>
learnByWork
查看>>
lua 函数
查看>>
Git的基本命令
查看>>
四平方和
查看>>
第十八周 12.27-1.2
查看>>
C# IP地址字符串和数值转换
查看>>