水题:UVa253-Cube painting
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
解题心得:
- 很简单的一个题,只要比较三个对面是否相等就可以了,只要三个对面相等,怎么安排都是一样的六面体。
反正都这么简单,代码就瞎写的
#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的更多相关文章
- [刷题]算法竞赛入门经典(第2版) 4-4/UVa253 - Cube painting
书上具体所有题目:http://pan.baidu.com/s/1hssH0KO 代码:(Accepted,0 ms) #include<iostream> char str[15]; v ...
- UVA253 Cube painting(数学)
题目链接. 分析: 用的<训练指南>上的方法.详见P17. 从6个面中选一个做顶面,再从剩下的4个面中选1个做正面,则此正方体唯一确定. 需要枚举共6*4=24种. #include &l ...
- uva253 Cube painting(UVA - 253)
题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相 ...
- HDU5053the Sum of Cube(水题)
HDU5053the Sum of Cube(水题) 题目链接 题目大意:给你L到N的范围,要求你求这个范围内的全部整数的立方和. 解题思路:注意不要用int的数相乘赋值给longlong的数,会溢出 ...
- UVA 253 Cube painting(暴力打表)
Cube painting Problem Description: We have a machine for painting cubes. It is supplied with three d ...
- uva 253 - Cube painting(相同骰子)
习题4-4 骰子涂色(Cube painting, UVa 253) 输入两个骰子,判断二者是否等价.每个骰子用6个字母表示,如图4-7所示. 图4-7 骰子涂色 例如rbgggr和rggbgr分别表 ...
- HDOJ 2317. Nasty Hacks 模拟水题
Nasty Hacks Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Tota ...
- ACM :漫漫上学路 -DP -水题
CSU 1772 漫漫上学路 Time Limit: 1000MS Memory Limit: 131072KB 64bit IO Format: %lld & %llu Submit ...
- ytu 1050:写一个函数,使给定的一个二维数组(3×3)转置,即行列互换(水题)
1050: 写一个函数,使给定的一个二维数组(3×3)转置,即行列互换 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 154 Solved: 112[ ...
随机推荐
- [软件工程基础]PhyLab 需求与功能分析改进文档
NABCD 模型 Need 需求 根据 Default 的需求文档,物理实验网站对于北航大二学生完成物理实验有较大的帮助,反馈较好.由于在 2016-2017 春季学期,网站数据库因为不明原因被删除了 ...
- Appium禁止appium setting和unlock在设备上重复安装
1.文件:/Applications/Appium.app/Contents/Resources/node_modules/appium/node_modules/appium-android-dri ...
- Linux--NiaoGe-Service-07网络安全与主机基本防护
Linux系统内自带的防火墙有两层: 第一层:数据包过滤防火墙:IP Filtering和Net Filter 要进入Linux本机的数据包都会先通过Linux预先内置的防火墙(Net Filter) ...
- WebService学习之旅(一)使用JAX-WS发布WebService
JAX-WS全称Java™ API for XML Web Services,是随着JDK1.6及其后续版本发布的方便Java程序员开发WebService应用的一组API,通常简称为JWS,目前版本 ...
- mac系统连接Android手机
1. 打开终端,输入:system_profiler SPUSBDataType,查看Mac系统所有USB设备信息,找到相应的厂商Vender ID 2.输入echo "Vender ID& ...
- H5移动端图片裁剪(base64)
在移动端开发的过程中,或许会遇到对图片裁剪的问题.当然遇到问题问题,不管你想什么方法都是要进行解决的,哪怕是丑点,难看点,都得去解决掉. 图片裁剪的jquery插件有很多,我也测试过很多,不过大多数都 ...
- DRBD+NFS+Keepalived高可用环境
1.前提条件 准备两台配置相同的服务器 2.安装DRBD [root@server139 ~]# yum -y update kernel kernel-devel [root@server139 ~ ...
- Heacher互助平台 α版本冲刺
课程属性 作业课程 https://edu.cnblogs.com/campus/xnsy/SoftwareEngineeringClass1/ 作业链接 https://edu.cnblogs.co ...
- HTML5微信播放全屏问题的解决方法
在ios和安卓手机里的微信下播放视频时,会遇到不少问题,例如需要手动点击,视频才会播放,并且视频会跳出微信框,出现控制条,如果视频不是腾讯视频,播放完毕会出现腾讯视频的广告推送等问题 解决办法:给vi ...
- 【Selenium-WebDriver问题点】driver和浏览器版本之间的兼容性问题
今天把手头有的一些关于selenium测试的资源整理了一下,分享出来. 1. 所有版本chrome下载 是不是很难找到老版本的chrome?博主收集了几个下载chrome老版本的网站,其中哪个下载的是 ...