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——题解的更多相关文章

  1. POJ2286 The Rotation Game

    Description The rotation game uses a # shaped board, which can hold 24 pieces of square blocks (see ...

  2. [poj2286]The Rotation Game (IDA*)

    //第一次在新博客里发文章好紧张怎么办 //MD巨神早已在一个小时前做完了 The Rotation Game Time Limit: 15000MS Memory Limit: 150000K To ...

  3. POJ2286 The Rotation Game(IDA*)

    The Rotation Game Time Limit: 15000MS   Memory Limit: 150000K Total Submissions: 5691   Accepted: 19 ...

  4. POJ2286 The Rotation Game[IDA*迭代加深搜索]

    The Rotation Game Time Limit: 15000MS   Memory Limit: 150000K Total Submissions: 6325   Accepted: 21 ...

  5. A*专题训练

    POJ2449 Remmarguts' Date UDF's capital consists of N stations. The hall is numbered S, while the sta ...

  6. The Rotation Game (POJ 2286) 题解

    [问题描述] (由于是英文的,看不懂,这里就把大意给大家说一下吧……都是中国人,相信大家也不愿意看英文……) 如图,一个井字形的棋盘,中间有着1-3任意的数,有ABCDEFGH八个操作,每个操作意味着 ...

  7. Hackerrank - Game Of Rotation 题解

    旋转一个数组以得到最大值. 陷阱就是:不能排序.须要模拟操作旋转,并设计公式计算旋转后的和. 要求是O(n)时间完毕. 原题: https://www.hackerrank.com/challenge ...

  8. 【题解】【数组】【查找】【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 ...

  9. UVA1434-The Rotation Game(迭代加深搜索)

    Problem UVA1434-The Rotation Game Accept:2209  Submit:203 Time Limit: 3000 mSec  Problem Description ...

随机推荐

  1. ubuntu16安装过程中的硬盘分区

    硬盘分区主要是三个区,如下图,分别是/,swap交换空间,/home,其中第一个分区/是主分区,建议至少8GB,要不ubuntu安装的时候放不下.

  2. Restify Api 开发经验

    此文已由作者王振华授权网易云社区发布. 欢迎访问网易云社区,了解更多网易技术产品运营经验. 工作期间,一直在用Restify开发或维护大大小小的API系统,现在分享一下一些个人觉得不错的Tips. 充 ...

  3. mysql表的核心元数据

    索引的 mysql> show indexes from recordsInRangeTest; +--------------------+------------+------------- ...

  4. ActiveMQ服务器之间传输对象,项目A发送对象到项目B接收发送对象《二》

    ActiveMQ服务器之间传输对象,项目A发送对象到项目B接收发送对象<一> 上一篇文章写到对象之间传输使用线程方式 ,无法使用监听方式,最近解决了使用监听方式接收对象,本次使用配置文件方 ...

  5. Paper Reading - Learning like a Child: Fast Novel Visual Concept Learning from Sentence Descriptions of Images ( ICCV 2015 )

    Link of the Paper: https://arxiv.org/pdf/1504.06692.pdf Innovations: The authors propose the Novel V ...

  6. 机器学习(四)正则化与过拟合问题 Regularization / The Problem of Overfitting

    文章内容均来自斯坦福大学的Andrew Ng教授讲解的Machine Learning课程,本文是针对该课程的个人学习笔记,如有疏漏,请以原课程所讲述内容为准.感谢博主Rachel Zhang 的个人 ...

  7. 20145214 《Java程序设计》第5周学习总结

    20145214 <Java程序设计>第5周学习总结 教材学习内容总结 try和catch Java中所有错误都会被包装为对象,可以尝试try执行程序并捕捉catch代表错误的对象后做一些 ...

  8. Divide two integers without using multiplication, division and mod operator.

    描述 不能使用乘法.除法和取模(mod)等运算,除开两个数得到结果,如果内存溢出则返回Integer类型的最大值.解释一下就是:输入两个数,第一个数是被除数dividend,第二个是除数divisor ...

  9. 二叉搜索树(BST)---python实现

    github:代码实现 本文算法均使用python3实现 1. 二叉搜索树定义   二叉搜索树(Binary Search Tree),又名二叉排序树(Binary Sort Tree).   二叉搜 ...

  10. iOS-加载html字符串

    NSMutableAttributedString * attrString =[[NSMutableAttributedString alloc] initWithData:[resultModel ...