ZOJ 2477 Magic Cube 暴力,模拟 难度:0
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=1477
用IDA*可能更好,但是既然时间宽裕数据简单,而且记录状态很麻烦,就直接暴力了
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cctype>
using namespace std;
char maz[54];
char readchar(){
char ch=0;
while(!isalpha(ch)){
ch=getchar();
}
return ch;
} const int cell[6][9]={//直接按照读取顺序来记录字符位置,所以需要记录那些位置在哪个面上
{4,0,1,2,3,5,6,7,8},{22,9,10,11,21,23,33,34,35},{25,12,13,14,24,26,36,37,38},
{28,15,16,17,27,29,39,40,41},{31,18,19,20,30,32,42,43,44},{49,45,46,47,48,50,51,52,53}
};
const int change[12][20]={//change[cnt][i]:第cnt种改变第i个移动的目的地,change[cnt^1][i]:第cnt种改变第i个移动的原地址
{11,23,35,34,33,21, 9,10,51,48,45,36,24,12, 6, 3, 0,20,32,44},
{ 9,10,11,23,35,34,33,21,36,24,12, 6, 3, 0,20,32,44,51,48,45},
{14,13,26,38,37,36,24,12,45,46,47,39,27,15, 8, 7, 6,11,23,35},
{12,24,13,14,26,38,37,36,39,27,15, 8, 7, 6,11,23,35,45,46,47},
{17,29,41,40,39,27,15,16,47,50,53,42,30,18, 2, 5, 8,14,26,38},
{15,16,17,29,41,40,39,27,42,30,18, 2, 5, 8,14,26,38,47,50,53},
{18,19,20,32,44,43,42,30,53,52,51,33,21, 9, 0, 1, 2,17,29,41},
{42,30,18,19,20,32,44,43,33,21, 9, 0, 1, 2,17,29,41,53,52,51},
{ 0, 1, 2, 5, 8, 7, 6, 3,12,13,14,15,16,17,18,19,20, 9,10,11},
{ 6, 3, 0, 1, 2, 5, 8, 7,15,16,17,18,19,20, 9,10,11,12,13,14},
{45,46,47,50,53,52,51,48,44,43,42,41,40,39,38,37,36,35,34,33},
{51,48,45,46,47,50,53,52,41,40,39,38,37,36,35,34,33,44,43,42}
};
bool ok(){
for(int i=0;i<6;i++){
for(int j=1;j<9;j++){
if(maz[cell[i][j]]!=maz[cell[i][0]])return false;
}
}
return true;
}
void rot(int ind){
char tmp[54];
copy(maz,maz+54,tmp);
for(int i=0;i<20;i++){
tmp[change[ind][i]]=maz[change[ind^1][i]];
}
copy(tmp,tmp+54,maz);
}
int ans[6];
bool dfs(int cnt){
if(cnt<=0)return ok();
char tmp[54];
copy(maz,maz+54,tmp);
for(int i=0;i<12;i++){
rot(i);
ans[cnt]=i;
if(dfs(cnt-1))return true;
copy(tmp,tmp+54,maz);
}
return false;
}
int main(){
int T;
scanf("%d",&T);
for(int ti=1;ti<=T;ti++){
for(int i=0;i<54;i++)maz[i]=readchar();
for(int i=0;i<=6;i++){
if(i==6){
puts("-1");
break;
}
else if(dfs(i)){
printf("%d\n",i);
for(int j=i;j>0;j--){
printf("%d %d\n",ans[j]/2,ans[j]&1?-1:1);
}
break;
}
}
}
return 0;
}
ZOJ 2477 Magic Cube 暴力,模拟 难度:0的更多相关文章
- ZOJ 2477 Magic Cube(魔方)
ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds Memory Limit: 65536 KB This is a very popular gam ...
- ZOJ 3654 Letty's Math Class 模拟 难度:0
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4844 题意:给你一个只包含中括号和正整数,+,-,结果在longlong范围内 ...
- hdu 4771 13 杭州 现场 B - Stealing Harry Potter's Precious 暴力bfs 难度:0
Description Harry Potter has some precious. For example, his invisible robe, his wand and his owl. W ...
- LeetCode 6 ZigZag Conversion 模拟 难度:0
https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...
- POJ 1573 Robot Motion 模拟 难度:0
#define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...
- POJ 2632 Crashing Robots 模拟 难度:0
http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...
- POJ 1068 Parencodings 模拟 难度:0
http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...
- 快速切题 sgu115. Calendar 模拟 难度:0
115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...
- 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0
Emag eht htiw Em Pleh Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2806 Accepted: ...
随机推荐
- ecnu1624求交集多边形面积
链接 本来在刷hdu的一道题..一直没过,看到谈论区发现有凹的,我这种方法只能过凸多边形的相交面积.. 就找来这道题试下水. 两个凸多边形相交的部分要么没有 要么也是凸多边形,那就可以把这部分单独拿出 ...
- JavaWeb学习总结(二)—http协议
http协议概念: * 即超文本传输协议.它规定了浏览器与服务器之间的通讯规则. * http是基于请求/响应模式的,所以分为请求协议和响应协议 http的类型: HTTP协议的版本:HTTP/1.0 ...
- VideoView
[1]这个控件就是对surfaceview 和 meidiaplayer进行封装 [2]meidiaplayer 播放视频他只支持 3gp MP4格式
- iOS开发之Xcode6 之手动添加Pch预编译文件
参考文档 http://blog.csdn.net/crazyzhang1990/article/details/44243343 红色部分为本人自己补充注意事项 在Xcode6之前,创建一个新工程x ...
- 列车时刻表查询 jqm/ajax/xml
<!doctype html><html lang="en"><head> <meta charset="UTF-8" ...
- error C2783: 无法为“T”推导 模板 参数
原则:“模板参数推导机制无法推导函数的返回值类型” 版本一: // 缺少<T> 参数 int n 对比第三个版本( 缺少<T> 参数 T n) ! 编译错误提示: 错误 1 e ...
- Android Toolbar样式定制详解
前言 Marterial Design出来也有一段时间了,为了紧跟Google的设计规范,决定在项目中使用Toolbar.使用了一段时间之后,发现很多时候原始的Toolbar并不能满足项目的要求.为了 ...
- 晒幸福, qq空间晒法
qq空间晒法 1.成为老婆之后,还是说新交的女朋友,这会让女朋友感动
- 串行通讯之.NET SerialPort
第1章串行通讯之.NET SerialPort 2 1 枚举串口 2 2 打开/关闭串口 2 3 写数据 3 3.1 写二进制数据 3 3.2 写文本数据 4 4 ...
- css_兼容IE和FF的写法
CSS对浏览器器的兼容性具有很高的价值,通常情况下IE和Firefox存在很大的解析差异,这里介绍一下兼容要点. 常见兼容问题: 1.DOCTYPE 影响 CSS 处理2.FF:div 设置 marg ...