POJ2286 The Rotation Game[IDA*迭代加深搜索]
| Time Limit: 15000MS | Memory Limit: 150000K | |
| Total Submissions: 6325 | Accepted: 2134 |
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
Source



#include<cstdio>
#include<iostream>
using namespace std;
const int N=;
int xh[N][N-]={
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,,
,,,,,,
};
int mid[]={,,,,,,,};
int rev[]={,,,,,,,};
int flag,cnt[];
int path[(int)1e5+];
char op[]="ABCDEFGH";
int s[];
inline int h(){
for(int i=;i<=;i++) cnt[i]=;
for(int i=;i<;i++) cnt[s[mid[i]]]++;
return -max(max(cnt[],cnt[]),cnt[]);
}
inline void move(int k){
int t=s[xh[k][]];
for(int i=;i<;i++) s[xh[k][i-]]=s[xh[k][i]];
s[xh[k][]]=t;
}
inline int check(){
int v=s[mid[]];
for(int i=;i<;i++) if(s[mid[i]]!=v) return ;
return ;
}
void dfs(int depth,int lim){
int H=h();
if(depth+H>lim) return ;
if(check()){flag=;return ;}
for(int i=;i<;i++){
move(i);
path[depth]=i;
dfs(depth+,lim);
if(flag) return ;
move(rev[i]);
}
}
int main(){
while(~scanf("%d",&s[])&&s[]){
for(int i=;i<;i++) scanf("%d",&s[i]);
flag=;
for(int i=;;i++){
dfs(,i);
if(flag){
if(i){
for(int j=;j<i;j++) putchar(op[path[j]]);
putchar('\n');
}
else puts("No moves needed");
printf("%d\n",s[mid[]]);
break;
}
}
}
return ;
}
POJ2286 The Rotation Game[IDA*迭代加深搜索]的更多相关文章
- HDU 1560 DNA sequence (IDA* 迭代加深 搜索)
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=1560 BFS题解:http://www.cnblogs.com/crazyapple/p/321810 ...
- uva 11212 - Editing a Book(迭代加深搜索 IDA*) 迭代加深搜索
迭代加深搜索 自己看的时候第一遍更本就看不懂..是非常水,但智商捉急也是没有办法的事情. 好在有几个同学已经是做过了这道题而且对迭代加深搜索的思路有了一定的了解,所以在某些不理解的地方询问了一下他们的 ...
- 埃及分数 迭代加深搜索 IDA*
迭代加深搜索 IDA* 首先枚举当前选择的分数个数上限maxd,进行迭代加深 之后进行估价,假设当前分数之和为a,目标分数为b,当前考虑分数为1/c,那么如果1/c×(maxd - d)< a ...
- UVA 1343 - The Rotation Game-[IDA*迭代加深搜索]
解题思路: 这是紫书上的一道题,一开始笔者按照书上的思路采用状态空间搜索,想了很多办法优化可是仍然超时,时间消耗大的原因是主要是: 1)状态转移代价很大,一次需要向八个方向寻找: 2)哈希表更新频繁: ...
- UVA 11212 Editing a Book [迭代加深搜索IDA*]
11212 Editing a Book You have n equal-length paragraphs numbered 1 to n. Now you want to arrange the ...
- BZOJ1085: [SCOI2005]骑士精神 [迭代加深搜索 IDA*]
1085: [SCOI2005]骑士精神 Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1800 Solved: 984[Submit][Statu ...
- 7-10Editing aBook uva11212(迭代加深搜索 IDA*)
题意: 给出n( 2<=n<=9) 个乱序的数组 要求拍成升序 每次 剪切一段加上粘贴一段算一次 拍成1 2 3 4 ...n即可 求排序次数 典型的状态空间搜索问题 ...
- hdu 1560 DNA sequence(迭代加深搜索)
DNA sequence Time Limit : 15000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) Total ...
- UVA11212-Editing a Book(迭代加深搜索)
Problem UVA11212-Editing a Book Accept:572 Submit:4428 Time Limit: 10000 mSec Problem Description ...
随机推荐
- ubuntu开启sshd服务(转)
SSH分客户端openssh-client和openssh-server如果你只是想登陆别的机器的SSH只需要安装openssh-client(ubuntu有默认安装,如果没有则sudo apt-ge ...
- wysiwyg+ckeditor 安装
1.下载wysiwyg模块 https://drupal.org/project/wysiwyg 2.下载ckeditor 上传/sites/all/libraries 出现问题: 解决方法: 在文 ...
- mongodb查询之从多种分类中获取各分类最新一条记录
mongodb查询之从多种分类中获取各分类最新一条记录 2017年04月06日 13:02:47 monkey_four 阅读数:6707更多 个人分类: MongoDBJavaScript 文章 ...
- 标题添加菜单HeaderContextMenu
<!DOCTYPE html><html><head> <meta charset="UTF-8"> <title>Co ...
- Android修改默认SharedPreferences文件的路径,SharedPreferences常用工具类
import android.app.Activity; import android.content.Context; import android.content.ContextWrapper; ...
- Windoows窗口程序三
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <windows.h& ...
- C/C++预处理指令
预处理指令 Preprocessor Directives define undef ifdef ifndef if endif else and elif line error include 预定 ...
- thinkphp3.2 常用入口文件
<?php define('DIR_SECURE_FILENAME', 'default.html'); define('APP_PATH','./index/'); //项目路径 requir ...
- imx6 i2c分析
本文主要分析: 1. i2c设备注册 2. i2c驱动注册 3. 上层调用过程参考: http://www.cnblogs.com/helloworldtoyou/p/5126618.html 1. ...
- Resource接口,及资源
Resource介绍 编码的时候,除了代码本身,我们还需要对外部的资源进行处理.例如:URL资源.URI资源.File资源.ClassPath相关资源.服务器相关资源(VFS等)等等. 而这些资源的处 ...