POJ2286:The Rotation Game——题解
http://poj.org/problem?id=2286
题目大意:如图所示有一种玩具,每次可以拉动A-H的开关使得整个行(或列)向字母方向移动一位(如果移动到头的话则到行(列)尾部)
求使得中间八个方格内数字相同的移动顺序(移动次数最小且字典序最小)和最终中间八个方格内的数的个数。

————————————————————————
说好的学完IDA*之后独立做了一道题,全程没查题解一遍AC。
对于IDA*是什么不了解的,可以看我的置顶骑士精神那道题。
首先估价函数简单点处理就是8-中间相同的数的最大个数。
然后枚举最终答案跑dfs即可,没什么太大难度(就是代码实现吗!)
#include<cstdio>
#include<cstring>
#include<cctype>
#include<iostream>
#include<map>
using namespace std;
int a[];
char dir[]={'A','B','C','D','E','F','G','H'};
int go[][]={{,,,,,,},
{,,,,,,},
{,,,,,,},
{,,,,,,},
{,,,,,,},
{,,,,,,},
{,,,,,,},
{,,,,,,}};
int arc[]={,,,,,,,};
int ans;
inline int h(){
int t[]={},res=;
for(int i=;i<=;i++)t[a[i]]++;
for(int i=;i<=;i++)t[a[i]]++;
for(int i=;i<=;i++)t[a[i]]++;
for(int i=;i<=;i++)res=max(res,t[i]);
return -res;
}
inline void turn(int k){
for(int i=;i<;i++){
swap(a[go[k][i]],a[go[k][i-]]);
}
return;
}
char realdir[];
inline bool dfs(int step){
if(step==ans){
if(!h())return ;
return ;
}
if(h()+step>ans)return ;
for(int i=;i<;i++){
turn(i);
if(dfs(step+)){
realdir[step]=i;
return ;
}
return ;
}
int main(){
while(scanf("%d",&a[])!=EOF&&a[]){
for(int i=;i<=;i++)scanf("%d",&a[i]);
for(ans=;;ans++){
if(dfs())break;
}
if(!ans)printf("No moves needed\n%d\n",a[]);
else{
for(int i=;i<ans;i++)printf("%c",dir[realdir[i]]);
printf("\n%d\n",a[]);
}
}
return ;
}
POJ2286:The Rotation Game——题解的更多相关文章
- POJ2286 The Rotation Game
Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see ...
- [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 ...
- The Rotation Game (POJ 2286) 题解
[问题描述] (由于是英文的,看不懂,这里就把大意给大家说一下吧……都是中国人,相信大家也不愿意看英文……) 如图,一个井字形的棋盘,中间有着1-3任意的数,有ABCDEFGH八个操作,每个操作意味着 ...
- Hackerrank - Game Of Rotation 题解
旋转一个数组以得到最大值. 陷阱就是:不能排序.须要模拟操作旋转,并设计公式计算旋转后的和. 要求是O(n)时间完毕. 原题: https://www.hackerrank.com/challenge ...
- 【题解】【数组】【查找】【Leetcode】Search in Rotated Sorted Array
Suppose a sorted array is rotated at some pivot unknown to you beforehand. (i.e., 0 1 2 4 5 6 7 migh ...
- UVA1434-The Rotation Game(迭代加深搜索)
Problem UVA1434-The Rotation Game Accept:2209 Submit:203 Time Limit: 3000 mSec Problem Description ...
随机推荐
- Docker - vim安装
在使用docker容器时,有时候里边没有安装vim,敲vim命令时提示说:vim: command not found,这个时候就需要安装vim. apt-get install vim 若提示: R ...
- Android 模拟器下载、编译及调试
Android 模拟器源码下载 Android 模拟器源码的下载与 Android AOSP 源码库的下载过程类似,可以参考 Google 官方提供的 Android 源码下载文档 来了解这个过程. ...
- thinkphp5保存远程图片到本地
代码 protected function saveImg($imgUrl){ $ext=strrchr($imgUrl,'.'); if(!in_array($ext,['.jpg','.png', ...
- (C#)原型模式—深复制与浅复制
1.原型模式 用原型实例指定创建对象的实例,并且通过拷贝这些原型创建新的对象. *原型模式隐藏了创建对象的细节,提高了性能. *浅复制:被复制对象的所有变量都含有与原来对象相同的值,而且所有对其他对象 ...
- Siki_Unity_1-3_Unity零基础入门_古迹探险
1-3 Unity零基础入门 古迹探险 任务1/2:资料下载 链接:https://pan.baidu.com/s/1jHVymNk 密码:rbob 任务3:工程的创建和打开 Project:古迹探险 ...
- [知识库:python-tornado]异步调用中的上下文控制Tornado stack context
异步调用中的上下文控制Tornado stack context https://www.zouyesheng.com/context-in-async-env.html 这篇文章真心不错, 非常透彻 ...
- M2功能规格说明书
1.目的: 这篇随笔是简述我们团队所做的工程所能实现的功能及方便用户的使用. 2.假定和约束: 我们先限定为本地连接数据库进行各种操作的实现.用户电脑中需要有FLASH工具及快播插件.其他只需要了解基 ...
- java实现屏幕共享的小程序
最近在做软件软件工程的课程设计,做一个用于实验室的屏幕监控系统,参考各种前人代码,最后领悟之后要转换自己的代码,初学者都是这样模仿过来的. 说到屏幕监控系统,有教师断和学生端, ...
- JavaScript初探系列之数组的基本操作
在程序语言中数组的重要性不言而喻,JavaScript中数组也是最常使用的对象之一,数组是值的有序集合,由于弱类型的原因,JavaScript中数组十分灵活.强大,不像是Java等强类型高级语言数组只 ...
- Ubuntu下FileZilla的安装
FileZilla是一个免费而且开源的FTP客户端软件,共有两种版本:客户端版本.服务器版本.FileZilla有条理的界面和管理多站点的简化方式使得FileZilla Client成为一个方便高效的 ...