[poj2286]The Rotation Game (IDA*)
//第一次在新博客里发文章好紧张怎么办
//MD巨神早已在一个小时前做完了
| Time Limit: 15000MS | Memory Limit: 150000K | |
| Total Submissions: 5950 | Accepted: 1992 |
Description

Initially, the blocks are placed on the board randomly. Your task is to move the blocks so that the eight blocks placed in the center square have the same symbol marked. There is only one type of valid move, which is to rotate one of the four lines, each consisting of seven blocks. That is, six blocks in the line are moved towards the head by one block and the head block is moved to the end of the line. The eight possible moves are marked with capital letters A to H. Figure 1 illustrates two consecutive moves, move A and move C from some initial configuration.
Input
Output
Sample Input
1 1 1 1 3 2 3 2 3 1 3 2 2 3 1 2 2 2 3 1 2 1 3 3
1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 3 3 3 3 3 3 3 3
0
Sample Output
AC
2
DDHH
2
------------------------------------------------------------------------------------------------------
poj英文题的尿性呵呵哒
大概就是把那个棋盘的abcdef轴旋转次数最少使得中间那几个数字相同(注意只有1,2,3)
那么先找规律,就是把输入数据的位置与abcdef对应
接下来因为搜索层数未知,dfs会TLE,bfs会MLE,所以容易想到ID搜索
先指定递归层数,然后迭代加深一层一层搜下去(有的说用二分但这种小数据反而更费时)
再看每一层的搜索方向
联想八数码问题(然而并不清楚八数码问题),发现每个状态都有最多递归的层数(八个位置贪心减去目前最多的数字个数)
那么写一个估价函数猜猜最多搜多少,如果超出了层数限制那就剪枝,这样就有了IDA*
(我在说些什么)
代码代码代码我要去睡
1 #include<stdio.h>
2 #include<stdlib.h>
3 #include<string.h>
4 #include<limits.h>
5 int min(int a,int b){
6 return a<b?a:b;
7 }
8 int lines[][]={
9 { , , ,,,,},// A
{ , , ,,,,},// B
{, , , , , , },// C
{,,,,,,},// D
{,,,, , , },//E
{,,,, , , },//F
{,,,,,,},//G
{ , , , , , ,},//H
};
int matrix[]={,,,,,,,};
int cross[];
char ans[];
int check(){
for(int i=;i<;i++)if(cross[matrix[]]!=cross[matrix[i]])return ;
return ;
}
int predict(){
int most=;
for(int i=;i<=;i++){
int a=;
for(int j=;j<;j++)if(cross[matrix[j]]!=i)a++;
most=min(most,a);
}
return most;
}
int rotate(int mode){
int le=cross[lines[mode][]];
for(int i=;i<;i++)cross[lines[mode][i]]=cross[lines[mode][i+]];
cross[lines[mode][]]=le;
return ;
}
int dfs(int dpt,int dptm){
if(dpt==dptm) return check();
if(dpt+predict()>dptm) return ;
for(int i=;i<;i++){
ans[dpt]=i+'A';
rotate(i);
if(dfs(dpt+,dptm)) return ;
if(i%==) rotate((i+)%);
else rotate((i+)%);
}
return ;
}
int main(){
while(scanf("%d",&cross[])!=EOF&&cross[]!=){
for(int i=;i<;i++) scanf("%d",&cross[i]);
if(check()) printf("No moves needed\n");
else{
int i=;
while(++i) if(dfs(,i)) break;
ans[i]='\0';
printf("%s\n",ans);
}
printf("%d\n",cross[matrix[]]);
}
return ;
}
[poj2286]The Rotation Game (IDA*)的更多相关文章
- POJ2286 The Rotation Game[IDA*迭代加深搜索]
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 6325 Accepted: 21 ...
- POJ2286 The Rotation Game(IDA*)
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 5691 Accepted: 19 ...
- HUD 1043 Eight 八数码问题 A*算法 1667 The Rotation Game IDA*算法
先是这周是搜索的题,网站:http://acm.hdu.edu.cn/webcontest/contest_show.php?cid=6041 主要内容是BFS,A*,IDA*,还有一道K短路的,.. ...
- POJ2286 The Rotation Game
Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see ...
- 7-12 The Rotation Game IDA*
状态搜索题目 一开始打算用bfs 但是图给的不是矩形图 有点难以下手 参考了 lrj 将图上所有的点进行标号 直接一个一维数组就解决了图的问题 并且明确了每个点的标号 处理起来十分方 ...
- hdu 1667 The Rotation Game ( IDA* )
题目大意: 给你一个“井”子状的board,对称的由24个方块组成,每个方块上有123三个数字中的一个.给你初始状态,共有八种变换方式,求字典序最小的最短的的变换路径使得,board中间的八个方块上数 ...
- POJ 2286 The Rotation Game IDA*
(再一次感谢学长幻灯片) ID A* 随便自己yy了一下. 额嗯 思路什么的都没有问题 就是改不对.. 无奈地删代码...边删边交. 删啊删 哎呦 AC了 ... ... ... 找删的那一段 . o ...
- A*专题训练
POJ2449 Remmarguts' Date UDF's capital consists of N stations. The hall is numbered S, while the sta ...
- 启发式搜索——A*算法
启发式搜索 启发式搜索是一种对搜索到的每一个位置进行评估,然后从评估的最优位置进行搜索直到目的地, 由于搜索时对每一个位置的评估是基于直观或经验的所有叫启发式搜索 A*算法 历史: 1964年Nils ...
随机推荐
- sql回滚
rollback是针对事务的,你如果没有在执行语句之前开启事务,那么无法rollback,建议你还是想别的办法吧,事务语句如下(sqlserver的给你借鉴):--开启事务begin tran --执 ...
- ServiceStack.Redis 使用教程
http://www.cnblogs.com/shanyou/archive/2011/11/10/2245082.html https://github.com/ServiceStack/Servi ...
- 【Pro ASP.NET MVC 3 Framework】.学习笔记.7.SportsStore:购物车
3 创建购物车 每个商品旁边都要显示Add to cart按钮.点击按钮后,会显示客户已经选中的商品的摘要,包括总金额.在购物车里,用户可以点击继续购物按钮返回product目录.也可以点击Check ...
- Linux命令学习手册-printf命令(转)
分类: LINUX 参考资料:http://sns.linuxpk.com/space-566-do-blog-id-15819.html printf FORMAT [ARGUMENT]... pr ...
- yii2框架安装
注意:先把php.ini里面的php_openssl.dll扩展打开 1.下载yii2框架的文件包yii-advanced-app-2.0.7 2.打开路径为advanced下面的init.bat ...
- C#:实现托盘
1.向窗体上添加如下控件:MenuStrip menuStrip1, NotifyIcon ni_frmMain,Timer timer1, ContentMenuStrip cms_notify.其 ...
- js的动态加载、缓存、更新以及复用
使用范围: OA.MIS.ERP等信息管理类的项目,暂时不考虑网站. 遇到的问题: 完成一个项目,往往需要引用很多js文件,比如jQuery.js.easyUI等.还有自己写的一些列js文件,那么这些 ...
- [HTML]页面间传值的五种方法
一.QueryString传值:1. 这是最简单的传值方式,但缺点是传的值会显示在浏览器的地址栏中且不能传递对象,只适用于传递简单的且安全性要求不高的整数值,例如: 2. 新建一个WEB项目,添加一个 ...
- SIM卡应用-OPN,PLMN,SPN
SIM卡应用 移动运营商已经将SIM卡用於很多不同的应用,下面列出了其中最主要的应 用∶ ·漫游应用∶确保手机可以在漫游之後选择缺省的运营商网络.一个SIM应用是可以在手机漫游到某个合作夥伴运营商网络 ...
- 1029 C语言文法定义与C程序的推导过程
1 阅读并理解提供给大家的C语言文法文件. 2 参考该文件写出一个自己好理解版的现实版的完整版的C语言文法. 3 给出一段C程序,写出用上述文法产生这段C程序的推导过程. program → exte ...