POJ2286 The Rotation Game
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
正解:迭代加深搜索(+大剪枝)
解题报告:
北大信息学夏令营一试第一题,当时考场上看没什么人做于是果断没做,考完再看才发现是个搜索题。
今天考试居然考到了这道题,好吧,就来填这个坑吧。
首先迭代加深,确定搜索深度上界(保证dfs不会gi),然后我们考虑各种奇奇怪怪的剪枝。
显然,我们会在最终得到中间的一圈全是1或2或3,不妨取一个目前已经数量最多的数字来做一个估价若已经超过上界,就直接返回。
还有一个剪枝,如果上一次往上移动,那么这一次就不要往下移动。
代码如下:
//It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#ifdef WIN32
#define OT "%I64d"
#else
#define OT "%lld"
#endif
using namespace std;
typedef long long LL;
/*
图形一览:
0 1
2 3
4 5 6 7 8 9 10
11 12
13 14 15 16 17 18 19
20 21
22 23
*/
int num[][]={{,,,,,,},{,,,,,,},{,,,,,,},{,,,,,,}};
int ying[]={,,,,,,,};
int center[]={,,,,,,,};
int a[];
int ans,sh;
char out[]; inline int getint()
{
int w=,q=;
char c=getchar();
while((c<'' || c>'') && c!='-') c=getchar();
if (c=='-') q=, c=getchar();
while (c>='' && c<='') w=w*+c-'', c=getchar();
return q ? -w : w;
} inline bool check(){
int xun=a[center[]];
for(int i=;i<=;i++) if(a[center[i]]!=xun) return false;
return true;
} inline void mov(int x){
int cun=a[num[x][]];
for(int i=;i<=;i++) {
a[num[x][i]]=a[num[x][i+]];
}
a[num[x][]]=cun;
} inline int count(int x){
int total=;
for(int i=;i<=;i++) if(a[center[i]]!=x) total++;
return total;
} inline int gu(){
return min( min(count(),count()) , count());
} inline void init(){
for(int i=;i<=;i++) for(int j=;j<=;j++) num[i][j]=num[ying[i]][-j];
ying[]=;
} inline bool dfs(int tim,int limit,int last){
if(check()){
//out[tim]=a[center[0]];
sh=a[center[]];
return true;
}
else {
if(gu()+tim>limit) return false;
for(int i=;i<;i++) {
if(ying[last]==i) continue;
out[tim]='A'+i;
mov(i);
if(dfs(tim+,limit,i)) return true;
mov(ying[i]);
}
}
return false;
} inline void solve(){
init();
while(){
a[]=getint();
if(!a[]) break;
for(int i=;i<=;i++) a[i]=getint(); if(check()) printf("No moves needed\n%d\n",a[center[]]);
else{
for(ans=;;ans++) {
if(dfs(,ans,)) break;
}
printf("%s",out);
printf("\n%d\n",sh);
}
memset(out,'\0',sizeof(out));
}
} int main()
{
solve();
return ;
}
POJ2286 The Rotation Game的更多相关文章
- [poj2286]The Rotation Game (IDA*)
//第一次在新博客里发文章好紧张怎么办 //MD巨神早已在一个小时前做完了 The Rotation Game Time Limit: 15000MS Memory Limit: 150000K To ...
- POJ2286 The Rotation Game(IDA*)
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 5691 Accepted: 19 ...
- POJ2286 The Rotation Game[IDA*迭代加深搜索]
The Rotation Game Time Limit: 15000MS Memory Limit: 150000K Total Submissions: 6325 Accepted: 21 ...
- A*专题训练
POJ2449 Remmarguts' Date UDF's capital consists of N stations. The hall is numbered S, while the sta ...
- POJ2286:The Rotation Game——题解
http://poj.org/problem?id=2286 题目大意:如图所示有一种玩具,每次可以拉动A-H的开关使得整个行(或列)向字母方向移动一位(如果移动到头的话则到行(列)尾部) 求使得中间 ...
- UVALive 7139 Rotation(矩阵前缀和)(2014 Asia Shanghai Regional Contest)
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=6 ...
- The Rotation Game(IDA*算法)
The Rotation Game Time Limit : 30000/15000ms (Java/Other) Memory Limit : 300000/150000K (Java/Othe ...
- unity3d 的Quaternion.identity和transform.rotation区别是什么
Quaternion.identity就是指Quaternion(0,0,0,0),就是每旋转前的初始角度,是一个确切的值,而transform.rotation是指本物体的角度,值是不确定的,比如可 ...
- ios layer 动画-(transform.rotation篇)
x轴旋转: CABasicAnimation *theAnimation; theAnimation=[CABasicAnimation animationWithKeyPath:@"tra ...
随机推荐
- java 14 -10 Calendar类以及练习
Calendar:它为特定瞬间与一组诸如 YEAR.MONTH.DAY_OF_MONTH.HOUR 等 日历字段之间的转换提供了一些方法, 并为操作日历字段(例如获得下星期的日期)提供了一些方法. 1 ...
- 报错"the geometry has no Z values"处理
); //将Z值设置为0 //IPoint point = (IPoint)pGeo; //point.Z = 0; } else { IZAwa ...
- [原创]CI持续集成系统环境---部署Gitlab环境完整记录
Gitlab是一个代码托管平台,在实际工作中,对代码管理十分有用. 废话不多说,下面是对我自己搭建的Gitlab环境做一记录: (1)安装 ------------------------------ ...
- Git技巧总结分享
接触Git有很长一段时间了,从最初的不懂到逐渐熟悉运用,相比于SVN,更热衷于Git这一款强大的版本控制工具. 废话不多说,下面对Git做了一些技巧总结,在此分享下,希望能帮助到一些喜欢Git的朋友们 ...
- 图片button
- 21SpringMvc_异步发送表单数据到Bean,并响应JSON文本返回(这篇可能是最重要的一篇了)
这篇文章实现三个功能:1.在jsp页面点击一个按钮,然后跳转到Action,在Action中把Emp(int id ,String salary,Data data)这个实体变成JSON格式返回到页面 ...
- CSS规则的执行顺序(转)
你对CSS规则的执行顺序是否了解,这里和大家分享一下,若两条规则具有相同的权值.起源及特殊性,那在样式表中最后出现的规则优先. 1.CSS规则之特殊性 首先来看一下这个例子将会发生的情形: <s ...
- XML CDATA的作用
操作XML文件时,如果允许用户输入内容,例如∶"< ".">"."/".""等,当生成XML时,会破坏了XM ...
- 微信开放平台,微信登陆第三方网站 提示redirect_uri 参数错误
在微信开放平台上我填写的回调域是:bbs.qiaoshisui.com/LoginApi/WeiXinCallBack,我构造的链接是:https://open.weixin.qq.com/conne ...
- [CareerCup] 14.5 Object Reflection 对象反射
14.5 Explain what object reflection is in Java and why it is useful. Java中的对象反射机制可以获得Java类和对象的反射信息,并 ...