水题: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[ ...
随机推荐
- POJ 1830 开关问题 高斯消元,自由变量个数
http://poj.org/problem?id=1830 如果开关s1操作一次,则会有s1(记住自己也会变).和s1连接的开关都会做一次操作. 那么设矩阵a[i][j]表示按下了开关j,开关i会被 ...
- 《JavaScript设计模式》笔记之第三章:封装和信息隐藏
第三章 创建对象的基本模式 方法一:门户大开型 var Book = function(isbn, title, author) { if(isbn == undefined ) throw ne ...
- vuex2 10分钟快速入门
因为太简单了,我直接就贴代码了~ #建立store.js import Vue from 'vue'; import Vuex from 'vuex'; Vue.use(Vuex) export de ...
- git与GitHub(一)
相信,很多初入前端者都会对git以及GitHub不太了解,而我当时也经历过各种面试大关,也都会问:你了解git和GitHub吗?那么今天先来说一说git. 那么什么是git? (以下转载自廖雪峰老师的 ...
- python第一模块数据类型
一·进制之间的转换 十进制转换为二进制:逆序取余法. 二进制转换为十进制:如1101 1*2^0 + 0*2^1 + 1*2^2 +1 十六进制转换为二进制:231 0010 0011 ...
- CF1059B Forgery
思路: 若某个位置是‘.’,说明不能在周围的8个位置下笔.在所有可以下笔的位置填充一次,看能否“包含”需要的图案即可. 实现: #include <iostream> using name ...
- org.apache.axis2.AxisFault: Service class XXXXX must have public as access Modifier解决方案
使用Axis2工具生成客户端调用辅助类后,编写客户端调用代码运行时报错,完整错误信息如下: log4j:WARN No appenders could be found for logger (org ...
- Android属性系统简介
1.简介 在android 系统中,为统一管理系统的属性,设计了一个统一的属性系统.每个属性都有一个名称和值,他们都是字符串格式.属性被大量使用在Android系统中,用来记录系统设置或进程之间的信息 ...
- 11gR2新特性---Gpnp守护进程
在这篇文章中,我们会对11gR2 新的守护进程(资源名称ora.gpnpd)进行介绍,其中包含的gpnp的功能,启动顺序和基本的诊断方法. gpnp全称为grid plug and play,该组件的 ...
- 77 最长公共子序列 (lintcode)
注意:因为开的空间是length+1的,对于字符串的下标计算要-1 class Solution { public: /* * @param A: A string * @param B: A str ...