水题: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[ ...
随机推荐
- [JLOI2016]圆的异或并
Description 在平面直角坐标系中给定N个圆.已知这些圆两两没有交点,即两圆的关系只存在相离和包含.求这些圆的异或面积并.异或面积并为:当一片区域在奇数个圆内则计算其面积,当一片区域在偶数个圆 ...
- Codeforces Round #397 by Kaspersky Lab and Barcelona Bootcamp (Div. 1 + Div. 2 combined) B
Description Kostya likes Codeforces contests very much. However, he is very disappointed that his so ...
- Function ereg() is deprecated in
PHP 5.3 ereg() 无法正常使用,提示"Function ereg() is deprecated Error".问题根源是php中有两种正则表示方法,一个是posix, ...
- nodejs Async 使用方法(解决多层回调嵌套)
由于nodejs是异步处理的,有时我们想同步从mysql里取出数据,最后在处理逻辑 就需要用到此扩展: 此扩展可以避免多层回调: 安装方法: npm install async 使用方法: 1.par ...
- DBAplus社群线上分享----Sharding-Sphere之Proxy初探
功能 Cobar Mycat Heisenberg Shark TDDL Sharding-JDBC 是否开源 开源 开源 开源 开源 部分开源 开源 架构模型 Proxy架构 Proxy架构 Pro ...
- Oracle/MySql/SQL Sqlserver分页查询
简述 简单概括一下Oracle,MySql,SQL Sqlserver这三个数据库的分页查询语句. Oracle分页查询 例:每页显示两条数据,现在要查询第二页,也就是第3-4条数据. 查询语句: s ...
- 在WIN7、WIN8中,将快捷方式锁定到任务栏,C#
其实很简单,使用 API 函数 ShellExecute,就可以解决这个问题. 首先添加引用 using System.Runtime.InteropServices; 代码如下: using Sys ...
- 实现如下语法的功能:var a = (5).plus(3).minus(6);
Number.prototype.plus= function(val){ return parseInt(this)+val; }; Number.prototype.minus= function ...
- 导入maven的java web项目运行报错找不到Spring监听器
本地成功运行的一个maven项目,在另一台机器复制下来并导入,运行时报错: java.lang.ClassNotFoundException: org.springframework.web.cont ...
- github小技巧之Creating a pull request 创建 pull 请求
创建一个 pull 请求是为了协作更改存储库.这些变化会产生一个分支,它确保主分支保持干净整洁. 与commits提交是不同的,提交是fork之后的一种操作. 在你可以打开一个 pull 请求之前,您 ...