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*感觉其他的解法都弱爆了..............想法活跃,时间,空间消耗很小,给它跪了 启发式搜索关 ...
随机推荐
- eclipse常用设置之项目分组查看
1.打开‘NaviNavigator’ 视图,windows-->show views->NaviNavigator; 2.在NaviNavigator视图下选择select workin ...
- 【LeetCode】1、Two Sum
题目等级:Easy 题目描述: Given an array of integers, return indices of the two numbers such that they add u ...
- swift-延时加载函数
//延时加载函数 func delayLoad(){ let time: NSTimeInterval = 2.0 let delay = dispatch_time(DISPATCH_TIME_NO ...
- Scrapy爬虫框架示意图汇总
- 44.bucket filter:统计各品牌最近一个月的平均价格
课程大纲 GET /tvs/sales/_search { "size": 0, "query": { "term": { &quo ...
- bupt summer training for 16 #8 ——字符串处理
https://vjudge.net/contest/175596#overview A.设第i次出现的位置左右端点分别为Li,Ri 初始化L0 = 0,则有ans = sum{ (L[i] - L[ ...
- Codeforces Round #412 (Div. 2)ABCD
tourist的剧毒contest,题干长到让人不想做... A.看不太懂题意直接看下面input output note n组里有两数不一样的一组就rated 否则单调不增为maybe,否则unra ...
- JavaSE 学习笔记之StringBuffer(十五)
--< java.lang >-- StringBuffer字符串缓冲区: 构造一个其中不带字符的字符串缓冲区,初始容量为 16 个字符. 特点: 1:可以对字符串内容进行修改. 2:是一 ...
- 中国省市区地址三级联动插件---jQuery Distpicker
插件描述:distpicker是一款可以实现中国省市区地址三级联动jQuery插件.它使用简单,简单设置即可完成中国省市区地址联动效果. [官网]https://fengyuanchen.github ...
- linux 各命令字 练习
=============================================================== ...