HDU 1667 The Rotation Game (A*迭代搜索)
题目大意:略
每次选择一个最大深度K,跑IDA*
估价函数H=8-中间8个格里出现次数最多的数的个数x,即把它填满这个数最少需要8-x次操作,如果dep+H>K,就跳出..
深搜的时候暴力修改,记录操作的方向,回溯再改回来就行了,根本不用把网格压进状态里嘛..
又水了一篇博客
#include <queue> #include <cstdio> #include <cstring> #include <algorithm> #define NN 2010 #define ll long long #define uint unsigned int #define ull unsigned long long #define inf 0x3f3f3f3f using namespace std;int ans[NN]; int mp[20][20],tmp[10]; int xx[]={1,1,2,2,3,3,3,3,3,3,3,4,4,5,5,5,5,5,5,5,6,6,7,7}; int yy[]={3,5,3,5,1,2,3,4,5,6,7,3,5,1,2,3,4,5,6,7,3,5,3,5}; int sum[5],op[NN],num; int esti() {int x,y;sum[1]=sum[2]=sum[3]=0;x=xx[6],y=yy[6],sum[mp[x][y]]++;x=xx[7],y=yy[7],sum[mp[x][y]]++;x=xx[8],y=yy[8],sum[mp[x][y]]++;x=xx[11],y=yy[11],sum[mp[x][y]]++;x=xx[12],y=yy[12],sum[mp[x][y]]++;x=xx[15],y=yy[15],sum[mp[x][y]]++;x=xx[16],y=yy[16],sum[mp[x][y]]++;x=xx[17],y=yy[17],sum[mp[x][y]]++;return 8-max(sum[1],max(sum[2],sum[3])); } void A(){for(int i=0;i<7;i++) mp[i][3]=mp[i+1][3];mp[7][3]=mp[0][3],mp[0][3]=0; } void B(){for(int i=0;i<7;i++) mp[i][5]=mp[i+1][5];mp[7][5]=mp[0][5],mp[0][5]=0; } void C(){for(int i=8;i>1;i--) mp[3][i]=mp[3][i-1];mp[3][1]=mp[3][8],mp[3][8]=0; } void D(){for(int i=8;i>1;i--) mp[5][i]=mp[5][i-1];mp[5][1]=mp[5][8],mp[5][8]=0; } void E(){for(int i=8;i>1;i--) mp[i][5]=mp[i-1][5];mp[1][5]=mp[8][5],mp[8][5]=0; } void F(){for(int i=8;i>1;i--) mp[i][3]=mp[i-1][3];mp[1][3]=mp[8][3],mp[8][3]=0; } void G(){for(int i=0;i<7;i++) mp[5][i]=mp[5][i+1];mp[5][7]=mp[5][0],mp[5][0]=0; } void H(){for(int i=0;i<7;i++) mp[3][i]=mp[3][i+1];mp[3][7]=mp[3][0],mp[3][0]=0; }int dfs(int dep,int ma) {if(esti()==0) return mp[3][3];if(dep>=ma) return 0;if(esti()>ma-dep) return 0;int ans;A();ans=dfs(dep+1,ma);F();if(ans){op[++num]=1;return ans;} B();ans=dfs(dep+1,ma);E();if(ans){op[++num]=2;return ans;} C();ans=dfs(dep+1,ma);H();if(ans){op[++num]=3;return ans;} D();ans=dfs(dep+1,ma);G();if(ans){op[++num]=4;return ans;} E();ans=dfs(dep+1,ma);B();if(ans){op[++num]=5;return ans;} F();ans=dfs(dep+1,ma);A();if(ans){op[++num]=6;return ans;} G();ans=dfs(dep+1,ma);D();if(ans){op[++num]=7;return ans;} H();ans=dfs(dep+1,ma);C();if(ans){op[++num]=8;return ans;} return 0; }int a[30]; int main() {//freopen("t2.in","r",stdin);while(scanf("%d",&a[0])&&a[0]!=0){ull S=0;num=0;mp[xx[0]][yy[0]]=a[0];for(int i=1;i<24;i++){scanf("%d",&a[i]);mp[xx[i]][yy[i]]=a[i];}int ans;ans=dfs(0,0);if(ans){printf("No moves needed\n%d\n",ans);continue;}for(int k=1;k<=500;k++){ans=dfs(0,k);if(ans){for(int i=num;i>=1;i--)printf("%c",op[i]+'A'-1);puts("");printf("%d\n",ans);break;}}}return 0; }
转载于:https://www.cnblogs.com/guapisolo/p/10011489.html
HDU 1667 The Rotation Game (A*迭代搜索)相关推荐
- HDU 1667 The Rotation Game
参考文章:http://blog.csdn.net/urecvbnkuhbh_54245df/article/details/5856756 The portal:http://acm.hdu.edu ...
- 【搜索进阶】HDU 1667 The Rotation Game
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1667 IDA*的入门题目,状态过多容易超内存,正好体现了IDA*的优势,每次操作移动能使一个数字进入中 ...
- hdu 1667:The Rotation Game
题目可以看IDA*学习笔记-HDU1667 The Rotation Game_ex_voda的博客-CSDN博客 关于如何存储这个条状数组,我们开一个大的矩阵数组装下来就行了.当然,特殊坐标单独开两 ...
- hdu 1667 The Rotation Game(IDA*)
题目大意: 有一个井字形结构的图形,每条线上7个数字(1,2,3,),每次可以从八个方向将一条线上的数字循环移动1个距离,问经过最少几次什么操作,可以将图形中间的八个方块变成同一种数字. 解题思路: ...
- HUD 1043 Eight 八数码问题 A*算法 1667 The Rotation Game IDA*算法
先是这周是搜索的题,网站:http://acm.hdu.edu.cn/webcontest/contest_show.php?cid=6041 主要内容是BFS,A*,IDA*,还有一道K短路的,.. ...
- hdu 1667(IDA*)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1667 思路:大牛说是IDA*的入门题=.=构造h()=8-max(1,2,3); max(1,2,3 ...
- 【HDU】3441 Rotation
题意:给出A和C(1<=A,C<=10^9),所有满足B * B * K + 1 = A * A, (K >= 0)的B,构成边长为B的正方形,等角度的围绕在一个小正方形的周围.用C ...
- hdu 1667 IDA*
第一道IDA*...... 给链接:点击打开链接 AC代码如下: #include <iostream> #include <cstring> #include <cst ...
- 杭电OJ分类题目(1)
原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(1) HDU Introduction HDU ...
最新文章
- 配置DispatcherServlet应该写/还是/*
- Java断言(assert)
- OpenCV视频加速Video acceleration的实例(附完整代码)
- selenium截图模糊_Selenium截屏 图片未加载的问题解决--【懒加载】
- 前端学习(2136):使用es6模块化出现Access to script at ‘file:///... ..from origin ‘null‘ has been blocked。。。错误
- genymotion 此应用与您的手机不兼容
- extract 模板 php,PHP自定义函数实现assign()数组分配到模板及extract()变量分配到模板功能示例...
- 二叉树的基本操作(C)
- Linux下更改Python的软连接
- phpquery类php,phpquery 最基础的例子
- iOS 点击返回键崩溃的未解之谜
- 2020年 - 年终总结
- 黑马程序员-Linux系统编程-01
- 基于Testbench的FPGA实物自动化测试环境设计
- cad计算机面积和周长,CAD怎么计算二维图形的面积和周长
- 05-数据科学的基础:数据收集之市场调查_01 市场调查概括
- 《未来简史:从智人到智神》笔记一——人类的新议题
- memcpy函数实现(c语言)
- EV SSL证书是什么意思?
- 用PS作出的3D字体