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*感觉其他的解法都弱爆了..............想法活跃,时间,空间消耗很小,给它跪了 启发式搜索关 ...
随机推荐
- kesci---2019大数据挑战赛预选赛---情感分析
一.预选赛题------文本情感分类模型 本预选赛要求选手建立文本情感分类模型,选手用训练好的模型对测试集中的文本情感进行预测,判断其情感为「Negative」或者「Positive」.所提交的结果按 ...
- HUD 1426 Sudoku Killer (DFS)
链接 : Here! 思路 : 记录下所有 "?" , 出现的位置, 然后 $DFS$ 一下, 对于每个位置来说都可以填充 $9$ 种数值, 然后对于判断填充是否合法需要三个标记数 ...
- SqlServer大数据的分区方案
这里介绍的是大数据量的维护日志的分区解决方案: 每个月1张数据表,1个分组文件.31个分区(按每天1个分区).... 为了日后维护方便,直接删除旧的日志数据文件就可以,而不需要去做分区压缩. --用的 ...
- 一、Scrapy入门教程
本文转载自以下链接:https://scrapy-chs.readthedocs.io/zh_CN/latest/intro/tutorial.html 在本篇教程中,我们假定您已经安装好Scrapy ...
- Centos 7 关闭firewall防火墙启用iptables防火墙
一.关闭firewall防火墙 1.停止firewall systemctl stop firewalld.service 2.禁止firewall开机启动 systemctl disable fir ...
- 使用vscode,新建.vue文件,tab自动生成vue代码模板
第一步: 新建模板并保存 文件 --> 首选项 --> 用户代码片段 --> 输入vue,选择vue.json -->复制 第三步中的模板内容中内容保存 第二步: 添加配置,让 ...
- python 未知
import timeimport requestsfrom bs4 import BeautifulSoupimport threading def format_str(s): return s. ...
- Spring整合Junit框架进行单元测试Demo
一.开发环境 eclipse版本:4.6.1 maven版本:3.3.3 junit版本:4.12 spring版本:4.1.5.RELEASE JDK版本:1.8.0_111 二.项目结构 图 三. ...
- windows下db2的一些使用心得(不含安装)
1.安装完成后开始菜单栏里会有一个 DB2 Command Window - Administrator 打开这个命令窗口 2.db2 db2,启动 3.list databse directory ...
- LMDB installation
Official Website: http://lmdb.readthedocs.io/en/release/ Install commands for Ubuntu: $ sudo apt-get ...