UVA253 Cube painting(数学)
题目链接。
分析:
用的《训练指南》上的方法。详见P17.
从6个面中选一个做顶面,再从剩下的4个面中选1个做正面,则此正方体唯一确定。
需要枚举共6*4=24种。
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring> using namespace std; const int maxn = ; int _left[] = {, , , , , };
int up[] = {, , , , , }; char s1[maxn], s2[maxn], s[maxn]; void rot(int *T, char *str) {
char t[maxn];
strcpy(t, str);
for(int i=; i<; i++) str[i] = t[T[i]];
} bool check() {
char t[maxn];
for(int i=; i<; i++) {
strcpy(t, s1);
if(i == ) rot(up, t);
else if(i == ) { rot(_left, t); rot(up, t); }
else if(i == ) { rot(up, t); rot(up, t); }
else if(i == ) { rot(_left, t); rot(_left, t); rot(up, t); }
else if(i == ) { rot(_left, t); rot(_left, t); rot(_left, t); rot(up, t); }
for(int i=; i<; i++) {
rot(_left, t);
if(strcmp(s2, t) == ) return ;
}
} return ;
} int main() { while(gets(s)) {
for(int i=; i<; i++) s1[i] = s[i];
s1[] = '\0'; for(int i=; i<; i++) s2[i-] = s[i];
s2[] = '\0'; if(check()) printf("TRUE\n");
else printf("FALSE\n");
} return ;
}
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(UVA - 253)
题目大意 输入有三种颜色判断两个骰子是否相同 思路(借鉴) ①先用string输入那12个字符,然后for出两个骰子各自的字符串 ②这里用的算法是先找出第一个的三个面与第二个的六个面去比较,如果找到相 ...
- 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分别表 ...
- Cube painting UVA - 253
We have a machine for painting cubes. It is supplied with three different colors: blue, red and gre ...
- HDU 1220 Cube(数学,找规律)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1220 Cube Time Limit: 2000/1000 MS (Java/Others) M ...
- UVA 253 Cube painting
大致题意:有三种颜色,一个立方体6面都可以涂一种颜色.现在给出两个每个面都涂好颜色的立方体,判断这两个立方体通过旋转是否相等. 立方体的旋转出来的结果有很多,首先可以0,1,2,3,4,5(顺序是:上 ...
- 骰子涂色 (Cube painting,UVa 253)
题目描述:算法竞赛入门习题4-4 题目思路:1.旋转其中一个骰子进行匹配 2.进行遍历,如果匹配,就进行相对面的匹配 3.三个对立面都匹配即是一样等价的 //没有按照原题的输入输出 #include ...
- UVA 253 Cube painting(枚举 模拟)
题意: 按如图的顺序给定2个骰子的颜色(只有r.b.g三种颜色) 问2个骰子是否一模一样 如 可表示为“rbgggr” 和 “rggbgr”, 第二个就是绕着Z轴顺时针旋转90度与第一个相同的骰子. ...
随机推荐
- 使用Listener准备application作用域数据
在程序中.有些数据我们希望在程序启动的时候就准备好,而且仅仅准备一次,放在application作用域中,这时候.我们一般会用Listener来准备这些数据. 可是,用Listener准备applic ...
- VC++获取网卡MAC、硬盘序列号、CPU ID、BIOS编号
以下代码可以取得系统特征码(网卡MAC.硬盘序列号.CPU ID.BIOS编号) BYTE szSystemInfo[4096]; // 在程序执行完毕后,此处存储取得的系统特征码 UINT uSys ...
- 关于 java.util.concurrent 您不知道的 5 件事--转
第 1 部分 http://www.ibm.com/developerworks/cn/java/j-5things4.html Concurrent Collections 是 Java™ 5 的巨 ...
- TCP/IP协议原理与应用笔记07:HTTP、TCP/IP与socket区别
1. TCP/IP协议与HTTP协议区别: HTTP 超文本传输协议(HTTP,HyperText Transfer Protocol)是互联网上应用最为广泛的一种网络协议.所有的WWW文件 ...
- Linux入门基础教程
转载自:http://www.centoscn.com/CentOS/2015/0528/5555.html 1. 1 Linux操作系统简介 Linux是一套免费使用和自由传播的类Unix ...
- .ignore插件自动忽略
AS自带的.ignore文件 在AS中新建项目时,默认会创建一个.ignore文件,其中默认忽略的是 *.iml .gradle /local.properties /.idea/workspace. ...
- Android 环境下编译FFmpeg
Android 环境下编译FFmpeg 开发环境:Ubuntu 12.04.2 LTS , android-sdk-linux, android-ndk-r8e 一 .X264 编译 1. X2 ...
- 转载:C#中事件和委托的编译代码
接上文转载:C#中事件的由来,这时候,我们注释掉编译错误的行,然后重新进行编译,再借助Reflactor来对 event的声明语句做一探究,看看为什么会发生这样的错误: public event Gr ...
- 使用ajax与服务器通信的步骤
使用ajax与服务器通信的步骤: 1. 创建一个XMLHttpRequest对象 2. 创建url,data,通过xmlHttpRequest.send() 3. 服务器端接收ajxa的请求,做相应处 ...
- SQL 插入查询的最大ID 号 进行批量
INSERT INTO tbl_image_language ( code, docomo_cd, au_cd, softbank_cd ) SELECT DISTINCT((SELECT max(c ...