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的更多相关文章

  1. ZOJ 2477 Magic Cube(魔方)

    ZOJ 2477 Magic Cube(魔方) Time Limit: 2 Seconds      Memory Limit: 65536 KB This is a very popular gam ...

  2. ZOJ 3654 Letty's Math Class 模拟 难度:0

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4844 题意:给你一个只包含中括号和正整数,+,-,结果在longlong范围内 ...

  3. 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 ...

  4. LeetCode 6 ZigZag Conversion 模拟 难度:0

    https://leetcode.com/problems/zigzag-conversion/ The string "PAYPALISHIRING" is written in ...

  5. POJ 1573 Robot Motion 模拟 难度:0

    #define ONLINE_JUDGE #include<cstdio> #include <cstring> #include <algorithm> usin ...

  6. POJ 2632 Crashing Robots 模拟 难度:0

    http://poj.org/problem?id=2632 #include<cstdio> #include <cstring> #include <algorith ...

  7. POJ 1068 Parencodings 模拟 难度:0

    http://poj.org/problem?id=1068 #include<cstdio> #include <cstring> using namespace std; ...

  8. 快速切题 sgu115. Calendar 模拟 难度:0

    115. Calendar time limit per test: 0.25 sec. memory limit per test: 4096 KB First year of new millen ...

  9. 快速切题 poj 2993 Emag eht htiw Em Pleh 模拟 难度:0

    Emag eht htiw Em Pleh Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2806   Accepted:  ...

随机推荐

  1. [转载] 高效 MacBook 工作环境配置

    原文: http://mp.weixin.qq.com/s?__biz=MjM5NzMyMjAwMA==&mid=208231200&idx=1&sn=8a76ddc56c1f ...

  2. web设计经验<六>令网站看起来不专业的10个设计误区

    不管你是不是一个羽翼未丰企业的领导,专业的网站能为你带来的东西比你想象的多很多.退一万步来说,“考虑到我们是一个小厂”,粗糙的网站也许能被用户理解,但是不一定能接受.每天大家所浏览的大量的网站,已经从 ...

  3. mysql 聚集函数需要注意的问题

    1.当没有记录的时候,使用聚集函数,会导致出现一条记录,记录的取值都是NULL,如下:mysql> select name from student where name='David';Emp ...

  4. mysql 大数据量求平均值

    需求是:对于一个设备,求一天内每个小时的平均值,一个月内每天的平均值,更通用的需求是,从起始时间到结束时间,每隔一段时间,求一个平均值.目前的解决策略是:在存储过程中进行处理,从起始时间到结束时间,切 ...

  5. 转载 uboot 命令

    1.bootm bootm [addr [arg ...]] - boot application image stored in memory passing arguments 'arg ...' ...

  6. stdlib标准库的常用API

    iOS 有如下四种随机数方法,下面以产生 [0,100) 的随机数为例: 1. srand((unsigned)time(0));  //不加这句每次产生的随机数不变 int i = rand() % ...

  7. 如何部署Scrapy 到Scrapyd上?

    安装上传工具 1.上传工具 scrapyd-client 2.安装方法: pip install scrapyd-client 3.上传方法: python d:\Python27\Scripts\s ...

  8. \r\n在php中有什么用

    \t \r \n 这是不是表现在html上的,你要看源代码才能看到效果,直接显示页面换行用<br />就可以了.\t \r \n 的话,你要用函数nl2br 才能在html页面上看到.写日 ...

  9. 图片左右滚动的js代码

    html代码 <div class="demo" id="demo" style="overflow:hidden; width:660px; ...

  10. OneProxy读写分离配置操作手册

    1.确保已配置好主备集群 A)配置 可参考MySQL官方文档(https://dev.mysql.com/doc/refman/5.6/en/replication-howto.html) 或者我的博 ...