UVA 253 立方体着色
来源:互联网 发布:java 时间校验 编辑:程序博客网 时间:2024/05/02 03:03
直观的做法是,分别绕着三种轴旋转,每种旋转有4种状态
然后枚举解空间,先写了个递归也能运行,但是速度没有那么快
#include <iostream>#include <sstream>#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <vector>#include <set>#include <cctype>#include <algorithm>#include <cmath>#include <deque>#include <map>using namespace std;///#define INF 0xffffff7#define MAXN 200 ///string state1, state2;int rotate1[] = {1, 4, 2, 5, 3, 6};int rotate2[] = {5, 1, 3, 4, 6, 2};int rotate3[] = {4, 2, 1, 6, 5, 3};void rotateFunc(int *method, string &content){int i, j;string exchange("");for (i = 0; i < 6; i++){exchange += content[method[i] - 1];}content = exchange;}bool dfs(string state1, int times){if (times == 9)return false;if (state1 == state2){return true;}else{times++;string temp = state1;rotateFunc(rotate1, state1);if (dfs(state1, times))return true;state1 = temp;rotateFunc(rotate2, state1);if (dfs(state1, times))return true;state1 = temp;rotateFunc(rotate3, state1);if (dfs(state1, times))return true;return false;}}int main(){///int i, j;string line;while (getline(cin, line)){state1 = line.substr(0, 6);state2 = line.substr(6, 12);if (dfs(state1, 0))cout << "TRUE" << endl;elsecout << "FALSE" << endl;} /// return 0;}
参考了一下其他解法
发现只要对面的颜色匹配,就一定可以找到旋转的方法
好残暴的解法
#include <iostream>#include <sstream>#include <cstdio>#include <cstring>#include <cmath>#include <string>#include <vector>#include <set>#include <cctype>#include <algorithm>#include <cmath>#include <deque>#include <map>using namespace std;///#define INF 0xffffff7#define MAXN 200 ///int main(){///int i, j;string line;while (getline(cin, line)){string line1, line2;line1 = line.substr(0, 6);line2 = line.substr(6, 12);bool IsOk = true;//对于每个对面进行比较for (i = 0; i < 3; i++){bool flag = false;//是否找到第二个cube对面与第一个匹配的for (j = 0; j < 6; j++){if (line1[i] == line2[j] && line1[5 - i] == line2[5 - j]){flag = true;line2[j] = '0';line2[5 - j] = '0';break;}}if (!flag){IsOk = false;break;}}//3个都能找到则肯定能旋转到,好残暴的解法if (IsOk)cout << "TRUE" << endl;elsecout << "FALSE" << endl;} /// return 0;}
- UVA 253 立方体着色
- UVa 253 立方体着色
- UVa 253 立方体着色
- UVA253-立方体着色
- UVA 253 - Cube painting(立方体涂色)
- 立方体的着色,阴影效果,过度效果
- UVA 193 图着色
- uva 10004 双着色
- UVa 193 图着色
- 193UVA图着色
- 立方体
- UVa Problem 10004 Bicoloring (双着色)
- UVa Problem 10051 Tower of Cubes (立方体之塔)
- UVA 12171 Sculpture 离散化 floodfil 立方体体积并 转换
- UVA 10755 Garbage Heap 最大子立方体和
- UVa 10755 Garbage Heap (最大价值子立方体+扫描法)
- 着色
- 着色
- xcode object-c 笔记
- vim 参考手册
- AIR-文件操作:使用文件对象操作文件和目录
- error:WINDOWS.H already included错误解释
- uboot执行流程
- UVA 253 立方体着色
- 不少美国人认为云计算跟天气有关 约会装B必备
- 在KVM 上访问 Linux 虚拟机终端
- 配置svn
- 配置trac
- 终于可以调试php了
- netbeans 7配置C/C++开发环境
- jira 的命令行工具
- python读取excel,操作数据库