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 ...
随机推荐
- smarty插件开发代替注册插件方法registerPlugin
- javascript中的队列结构
1.概念 队列和栈结构不同,栈是一种后进先出的结构,而队列是一种先进先出的结构.队列也是一种表结构,不同的是队列只能在队尾插入元素,在队首删除元素,可以将队列想象成一个在超时等待排队付钱的队伍,或者在 ...
- action中result没有值
action中result没有值,访问action会输出action中的所有数据,输出类型为.action类型 .
- 变态跳台阶-一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法。
class Solution { public: int jumpFloorII(int number) { ) ; ) ; *jumpFloorII(number-); } };
- C语言 const常量讲解
//const的本质 //const本质上是伪常量,无法用于数组初始化以及全局变量初始化 //原因在于const仅仅限定变量无法直接赋值,但是却可以通过指针间接赋值 //例如局部常量在栈区,而不在静态 ...
- SpringMVC Controller介绍(转)
SpringMVC Controller 介绍 一.简介 在SpringMVC 中,控制器Controller 负责处理由DispatcherServlet 分发的请求,它把用户请求的数据经过业务处理 ...
- jsp的三种自定义标签 写法示例
1.自定义方法标签 引入方式示例: <%@ taglib prefix="fns" uri="/WEB-INF/tlds/fns.tld" %> 写 ...
- [iOS翻译]《The Swift Programming Language》系列:Welcome to Swift-01
注:CocoaChina翻译小组已着手此书及相关资料的翻译,楼主也加入了,多人协作后的完整译本将很快让大家看到. 翻译群:291864979,想加入的同学请进此群哦.(本系列不再更新,但协作翻译的进度 ...
- Git初级使用教程(转)
http://www.cnblogs.com/xiaogangqq123/archive/2012/03/19/2405805.html 什么是 Git? Git 是一款免费的.开源的.分布式的版本控 ...
- 『Asp.Net 组件』Asp.Net 服务器组件 内嵌JS:让自己的控件动起来
代码: using System; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; namespace ...