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度与第一个相同的骰子. ...
随机推荐
- strus2与spring3 mvc的差别
比较了一下strus2与spring3 mvc的差别: spring3 mvc是方法级别的拦截,拦截到方法后根据参数上的注解,把request数据注入进去,在spring3mvc中,一个方法对应一个r ...
- jq實現網頁個性title
<!DOCTYPE html> <html content="text/html; charset=UTF-8"> <title>tooltip ...
- 关于C++构造函数的FAQ
[1] 构造函数是用来干什么的? 构造函数构建类的对象,初始化类变量,分配资源(内存.文件.信号量.套接口等等) [2] List x; 和 List x();有什么不同? 前一个是定义List的一个 ...
- 简单说明Python中的装饰器的用法
简单说明Python中的装饰器的用法 这篇文章主要简单说明了Python中的装饰器的用法,装饰器在Python的进阶学习中非常重要,示例代码基于Python2.x,需要的朋友可以参考下 装饰器对与 ...
- Android应用程序开发之图片操作(一)——Bitmap,surfaceview,imageview,Canvas
Android应用程序开发之图片操作(一)——Bitmap,surfaceview,imageview,Canvas 1,Bitmap对象的获取 首先说一下Bitmap,Bitmap是Androi ...
- cancel-ng-swipe-right-on-child
<!DOCTYPE html> <html lang="en" ng-app="myapp"> <head> <met ...
- PHP magic_quotes_gpc的详细使用方法
工作中遇到的代码 if (ini_get('magic_quotes_gpc')) { function stripslashesRecursive(array $array){ foreach ($ ...
- c#隐式转换之有符号位转换
有符号位类型的转换,额外的高位用源表达式的符号位填充.这样就维持了被转换的值的正确符号和大小. 特别注意的是负数的转换,额外的高位用1填充,因为负数的二进制表示是对应正数的二进制取反加1,所以高位用1 ...
- JqueryAjax
1. 2. 3. 4. 5. 6. 7.
- 低字节序和高字节序相互转换(Little Endian/Big Endian)
这个例子展示了如何转换整形数字的字节顺序,该方法可以用来在little-endian和big-endian之间转换. 说明:Windos(x86,x64)和Linux(x86,x64)都是little ...