POJ 2286 The Rotation Game IDA*
(再一次感谢学长幻灯片)
ID A* 随便自己yy了一下。
额嗯 思路什么的都没有问题 就是改不对。。
无奈地删代码。。。边删边交。 删啊删
哎呦 AC了
。。。
。。。
。。。
找删的那一段 。
oh
原来 d[i]^1!=f 要改成(d[i]^1)!=f 优先级问题 无奈了。。
#include<cstdio>
#include<algorithm>
using namespace std;
char t,a[25],b[25],d[]={0,2,4,7,3,1,6,5},ch[]={7,8,9,12,13,16,17,18};
char R[8][7]={{1,3,7,12,16,21,23},{23,21,16,12,7,3,1},{2,4,9,13,18,22,24},{24,22,18,13,9,4,2},{11,10,9,8,7,6,5},{5,6,7,8,9,10,11},{14,15,16,17,18,19,20},{20,19,18,17,16,15,14}};
void r(int x){
int jy=a[R[x][0]];
for(char i=1;i<7;i++)a[R[x][i-1]]=a[R[x][i]];
a[R[x][6]]=jy;
}
bool check(){
for(int i=1;i<=7;i++)
if(a[ch[i]]!=a[ch[0]])return 0;
return 1;
}
char g(){
char cnt[]={0,0,0};
for(char i=0;i<=7;i++)cnt[a[ch[i]]-1]++;
return 8-max(cnt[0],max(cnt[1],cnt[2]));
}
bool dfs(char f,char x){
if(x>t)return 0;
for(char i=0;i<8;i++)
if((d[i]^1)!=f&&g()+x<=t+1){
r(d[i]);
b[x]=i+'A';
if(check()||dfs(d[i],x+1))return 1;
r(d[i]^1);
}
return 0;
}
int main(){
while(scanf("%d",&a[1])&&a[1]){
for(char i=2;i<=24;i++)scanf("%d",&a[i]);
if(check()){printf("No moves needed\n%d\n",a[ch[0]]);continue;}
for(t=1;;t++)if(dfs(10,1))break;
for(char i=1;i<=t;i++)printf("%c",b[i]);
printf("\n%d\n",a[ch[0]]);
}
}
// by Sirius_Ren
#include <cstdio>
using namespace std;
short t,a[25],b[25],d[]={0,2,4,7,3,1,6,5},ch[]={7,8,9,12,13,16,17,18};
short R[8][7]={{1,3,7,12,16,21,23},{23,21,16,12,7,3,1},{2,4,9,13,18,22,24},{24,22,18,13,9,4,2},{11,10,9,8,7,6,5},{5,6,7,8,9,10,11},{14,15,16,17,18,19,20},{20,19,18,17,16,15,14}};
void r(int x){int jy=a[R[x][0]];for(int i=1;i<7;i++)a[R[x][i-1]]=a[R[x][i]];a[R[x][6]]=jy;}
short max(short a,short b,short c){int t=a>b?a:b;return t>c?t:c;}
bool check(){for(int i=1;i<=7;i++)if(a[ch[i]]!=a[ch[0]])return false;return true;}
short g(){
int cnt[]={0,0,0};
for(int i=0;i<=7;i++)cnt[a[ch[i]]-1]++;
return 8-max(cnt[0],cnt[1],cnt[2]);
}
bool dfs(int f,int x){
if(x>t)return false;
for(int i=0;i<8;i++)
if((d[i]^1)!=f&&g()+x<=t+1){
r(d[i]);
b[x]=i+'A';
if(check()||dfs(d[i],x+1))return true;
r(d[i]^1);
}
return false;
}
int main(){
while(scanf("%d",&a[1])&&a[1]){
for(int i=2;i<=24;i++)scanf("%d",&a[i]);
if(check()){printf("No moves needed\n%d\n",a[ch[0]]);continue;}
for(t=1;;t++)if(dfs(10,1))break;
for(int i=1;i<=t;i++)printf("%c",b[i]);
printf("\n%d\n",a[ch[0]]);
}
}
WA 的惨痛教训
最后一次AC 成功把code length刷到第一。
POJ 2286 The Rotation Game IDA*的更多相关文章
- POJ 2286 The Rotation Game(IDA*)
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 6396 Accepted: 21 ...
- POJ - 2286 - The Rotation Game (IDA*)
IDA*算法,即迭代加深的A*算法.实际上就是迭代加深+DFS+估价函数 题目传送:The Rotation Game AC代码: #include <map> #include < ...
- POJ 2286 The Rotation Game 迭代搜索深度 + A* == IDA*
感觉这样的算法还是比較局限的吧,反复搜索是一个不好的地方,并且须要高效的估值函数来进行强剪枝,这点比較困难. 迭代搜索深度是一个比較炫酷的搜索方式,只是有点拿时间换空间的感觉. 首先迭代深度比較搓的写 ...
- [poj] 2286 The Rotation Game || ID-DFS
原题 有1234四个数字,每个数字八个.有八种方向的移动,使得操作后中间八个方块的数字相同,求最小操作步数. 对于这种求最小步数的看起来就是dfs的题,就ID-DFS就好了. //不知道为什么都是ID ...
- 【POJ 2286】 The Rotation Game
[题目链接] http://poj.org/problem?id=2286 [算法] IDA* [代码] #include <algorithm> #include <bitset& ...
- The Rotation Game (POJ 2286) 题解
[问题描述] (由于是英文的,看不懂,这里就把大意给大家说一下吧……都是中国人,相信大家也不愿意看英文……) 如图,一个井字形的棋盘,中间有着1-3任意的数,有ABCDEFGH八个操作,每个操作意味着 ...
- [poj2286]The Rotation Game (IDA*)
//第一次在新博客里发文章好紧张怎么办 //MD巨神早已在一个小时前做完了 The Rotation Game Time Limit: 15000MS Memory Limit: 150000K To ...
- HUD 1043 Eight 八数码问题 A*算法 1667 The Rotation Game IDA*算法
先是这周是搜索的题,网站:http://acm.hdu.edu.cn/webcontest/contest_show.php?cid=6041 主要内容是BFS,A*,IDA*,还有一道K短路的,.. ...
- POJ 1077 HDU 1043 Eight (IDA*)
题意就不用再说明了吧......如此经典 之前想用双向广搜.a*来写,但总觉得无力,现在用IDA*感觉其他的解法都弱爆了..............想法活跃,时间,空间消耗很小,给它跪了 启发式搜索关 ...
随机推荐
- todey
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1"/> 框架集fromset ...
- 零基础学习Linux培训,应该选择哪个培训班?
云计算早已不是什么稀奇的概念,它的火爆让Linux运维工程师这个职业越来越重要.在当今各类云平台提供的系统中,Linux系统几乎毫无争议的独占鳌头,市场份额进一步扩张. 这也让Linux运维工程师职位 ...
- lua_note_01_lua介绍
1. lua 1. lua 1.1. lua介绍 1.2. Lua 特性 1.3. 特点 1.4. Lua 应用场景 1.5. 环境搭建 1.6. VS lua 1.1. lua介绍 Lua 是一种轻 ...
- =、==、is、id(内容)
= 赋值 == 比较值是否相等 is 比较.比较的是内存地址 id(内容) 测出内存地址
- python文件头的含义
一.指定解释器及其路径 在Linux\Mac上,可以用./文件路径直接运行.py文件 这时,需要在python文件开头指定解释器及其路径 #!/usr/bin/python 这样系统就直接按pytho ...
- Maven学习总结(2)——Maven项目构建过程练习
Maven学习总结(二)--Maven项目构建过程练习 上一篇只是简单介绍了一下maven入门的一些相关知识,这一篇主要是体验一下Maven高度自动化构建项目的过程 一.创建Maven项目 1.1.建 ...
- ACdream 1032 Component
Component Time Limit: 5000ms Memory Limit: 64000KB This problem will be judged on ACdream. Original ...
- POJ2001 Shortest Prefixes (Trie树)
直接用Trie树即可. 每个节点统计经过该点的单词数,遍历时当经过的单词数为1时即为合法的前缀. type arr=record next:array['a'..'z'] of longint; w: ...
- 刷新PHP缓冲区
为你的站点加速_php技巧 在当前 PHP 版本的默认配置下,“输出缓冲(Output Buffering)”是被打开的.旧版本则不是这样,在旧版本的 PHP 中,字符串在每次被输出的时候(通过 ec ...
- 洛谷 P3496 [POI2010]GIL-Guilds
P3496 [POI2010]GIL-Guilds 题目描述 King Byteasar faces a serious matter. Two competing trade organisatio ...