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. JAVA面试中问及HIBERNATE与 MYBATIS的对比

    第一方面:开发速度的对比 就开发速度而言,Hibernate的真正掌握要比Mybatis来得难些.Mybatis框架相对简单很容易上手,但也相对简陋些.个人觉得要用好Mybatis还是首先要先理解好H ...

  2. PLSQL-包函数存储过程

    包: 包是PLSQL中多个单元的逻辑组合,他将过程组合在一个包内容,以供用户调用,使用后,不需要程序员频繁的修改程序,可以保持程序的逻辑完整性,对包中的过程重新定义或者编译,以便修改部分功能,从而更好 ...

  3. 「日常训练」 Counting Cliques(HDU-5952)

    题意与分析 题源:2016ACM/ICPC沈阳现场赛. 这题让我知道了什么是团,不过最恶心的还是这题的数据了,卡了无数次- - 解决方法是维护一个G数组,不能去遍历邻接矩阵.至少我改了这么一个地方就过 ...

  4. 【WXS数据类型】Boolean

    属性: 名称 值类型 说明 [Boolean].constructor [String] 返回值为“Boolean”,表示类型的结构字符串 方法: 原型:[Boolean].toString() 说明 ...

  5. lintcode433 岛屿的个数

    岛屿的个数 给一个01矩阵,求不同的岛屿的个数. 0代表海,1代表岛,如果两个1相邻,那么这两个1属于同一个岛.我们只考虑上下左右为相邻. 您在真实的面试中是否遇到过这个题? Yes 样例 在矩阵: ...

  6. mvc中actionresult的返回值类型

    以前一直没注意actionresult都能返回哪些类型的类型值(一直用的公司的内部工具类初始化进行返回的),今天跟大家分享一下(也是转载的别人的日志qaq). 首先我们了解一下对action的要求: ...

  7. kubernetes相关

    1.获取client , api-server 加token 或in-cluster方式 2.所有对象均有list update get 等方法 3.对象属性源码追踪,yaml与源码一一对应 4.一些 ...

  8. [递推+矩阵快速幂]Codeforces 1117D - Magic Gems

    传送门:Educational Codeforces Round 60 – D   题意: 给定N,M(n <1e18,m <= 100) 一个magic gem可以分裂成M个普通的gem ...

  9. Python3 Tkinter-OptionMenu

    1.创建 from tkinter import * root=Tk() v=StringVar() v.set('xs') om=OptionMenu(root,v,'Python','PHP',' ...

  10. POJ 2187 Beauty Contest(凸包+旋转卡壳)

    Description Bessie, Farmer John's prize cow, has just won first place in a bovine beauty contest, ea ...