【题目链接】

http://poj.org/problem?id=2286

【算法】

IDA*

【代码】

#include <algorithm>
#include <bitset>
#include <cctype>
#include <cerrno>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <limits>
#include <list>
#include <map>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <utility>
#include <vector>
#include <cwchar>
#include <cwctype>
#include <stack>
#include <limits.h>
using namespace std;
const int A[] = {,,,,,,};
const int B[] = {,,,,,,};
const int C[] = {,,,,,,};
const int D[] = {,,,,,,}; int i,step;
int a[];
char path[]; inline void print()
{
int i;
for (i = ; i <= step; i++) printf("%c",path[i]);
printf("\n%d\n",a[]);
}
inline int f()
{
int i,m;
int s[];
memset(s,,sizeof(s));
s[a[]]++;
s[a[]]++;
s[a[]]++;
s[a[]]++;
s[a[]]++;
s[a[]]++;
s[a[]]++;
s[a[]]++;
m = ;
for (i = ; i <= ; i++) m = max(m,s[i]);
return - m;
}
inline bool check()
{
if (a[] == a[] && a[] == a[] && a[] == a[] && a[] == a[] && a[] == a[] && a[] == a[] && a[] == a[])
return true;
else return false;
}
inline bool IDDFS(int dep)
{
int i,tmp;
int b[];
if (dep > step)
{
if (check())
{
print();
return true;
}
else return false;
}
if (dep - + f() > step) return false;
for (i = ; i < ; i++) b[A[i]] = a[A[i]];
path[dep] = 'A';
tmp = a[A[]];
for (i = ; i < ; i++) a[A[i]] = a[A[i+]];
a[A[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[A[i]] = b[A[i]];
for (i = ; i < ; i++) b[B[i]] = a[B[i]];
path[dep] = 'B';
tmp = a[B[]];
for (i = ; i < ; i++) a[B[i]] = a[B[i+]];
a[B[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[B[i]] = b[B[i]];
for (i = ; i < ; i++) b[C[i]] = a[C[i]];
path[dep] = 'C';
tmp = a[C[]];
for (i = ; i >= ; i--) a[C[i]] = a[C[i-]];
a[C[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[C[i]] = b[C[i]];
for (i = ; i < ; i++) b[D[i]] = a[D[i]];
path[dep] = 'D';
tmp = a[D[]];
for (i = ; i >= ; i--) a[D[i]] = a[D[i-]];
a[D[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[D[i]] = b[D[i]];
for (i = ; i < ; i++) b[B[i]] = a[B[i]];
path[dep] = 'E';
tmp = a[B[]];
for (i = ; i >= ; i--) a[B[i]] = a[B[i-]];
a[B[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[B[i]] = b[B[i]];
for (i = ; i < ; i++) b[A[i]] = a[A[i]];
path[dep] = 'F';
tmp = a[A[]];
for (i = ; i >= ; i--) a[A[i]] = a[A[i-]];
a[A[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[A[i]] = b[A[i]];
for (i = ; i < ; i++) b[D[i]] = a[D[i]];
path[dep] = 'G';
tmp = a[D[]];
for (i = ; i < ; i++) a[D[i]] = a[D[i+]];
a[D[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[D[i]] = b[D[i]];
for (i = ; i < ; i++) b[C[i]] = a[C[i]];
path[dep] = 'H';
tmp = a[C[]];
for (i = ; i < ; i++) a[C[i]] = a[C[i+]];
a[C[]] = tmp;
if (IDDFS(dep+))
return true;
for (i = ; i < ; i++) a[C[i]] = b[C[i]];
return false;
} int main()
{ while (scanf("%d",&a[]) && a[])
{
for (i = ; i <= ; i++) scanf("%d",&a[i]);
if (check())
{
printf("No moves needed\n");
printf("%d\n",a[]);
continue;
}
for (i = ; i <= ; i++)
{
step = i;
if (IDDFS()) break;
}
} return ; }

【POJ 2286】 The Rotation Game的更多相关文章

  1. 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)

    [POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS   Memory Limit: 65536K Total Submiss ...

  2. bzoj 2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...

  3. 【链表】BZOJ 2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 382  Solved: 111[Submit][S ...

  4. BZOJ2288: 【POJ Challenge】生日礼物

    2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 284  Solved: 82[Submit][St ...

  5. BZOJ2293: 【POJ Challenge】吉他英雄

    2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 80  Solved: 59[Submit][Stat ...

  6. BZOJ2287: 【POJ Challenge】消失之物

    2287: [POJ Challenge]消失之物 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 254  Solved: 140[Submit][S ...

  7. BZOJ2295: 【POJ Challenge】我爱你啊

    2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 126  Solved: 90[Submit][Sta ...

  8. BZOJ2296: 【POJ Challenge】随机种子

    2296: [POJ Challenge]随机种子 Time Limit: 1 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 114  Solv ...

  9. BZOJ2292: 【POJ Challenge 】永远挑战

    2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 513  Solved: 201[Submit][ ...

随机推荐

  1. CSS3之 transform和animation区别

    CSS3 有3种和动画相关的属性:transform, transition, animation.其中 transform 描述了元素静态样式.而transition 和 animation 却都能 ...

  2. Hadoop学习笔记(一)Hadoop的单节点安装

    要想深入学习Hadoop分布式文件系统,首先需要搭建Hadoop的实验环境,Hadoop有两种安装模式,即单节点集群模式安装(也称为伪分布式)和完全分布式模式安装,本节只介绍单节点模式的安装,参考官方 ...

  3. 英语之ASIC

    ASIC(Application Specific Integrated Circuit) = 专用集成电路 assign = [计][数] 赋值 assign a value 分配一个值:赋值

  4. Assembly之instruction之Register Mode

    Assembler Code Content of ROM MOV R10,R11 MOV R10,R11 Length: One or two words Operation: Move the c ...

  5. Fish:Linux中比bash或zsh更好用的Shell

    Fish是一个智能且用户友好的命令行shell,适用于macOS,Linux和其他家族.fish包含语法突出显示.根据你键入字符自动提示autosuggest-as-type和花式选项卡完成等功能,无 ...

  6. springboot:基础学习一 linux下后台启动springboot项目

    我们知道启动springboot的项目有三种方式: 运行主方法启动 使用命令 mvn spring-boot:run”在命令行启动该应用 运行“mvn package”进行打包时,会打包成一个可以直接 ...

  7. windows7下搭建HTTP服务器

      打开控制面板,选择并进入“程序”,双击“打开或关闭Windows服务”,在弹出的窗口中选择“Internet信息服务”下面所有地选项,点击确定后,开始更新服务. 2 更新完成后,打开浏览器,输入“ ...

  8. jboss的下载安装、环境变量配置以及部署

    1. 下载安装 http://jbossas.jboss.org/downloads/   jdk为1.7 我下载的是:JBoss AS7.1.1.Final 2. 解压安装包  D:\program ...

  9. eas之排序接口

    KDTable目前本身并不支持排序功能,但提供了排序的接口,用户通过实现该接口(ISortManager)即可实现排序的功能.同时KDTable提供了一个简单实现KDTSortManager,这个类完 ...

  10. 在LinuxMint19上安装搜狗拼音输入法

    写在前面 由于Linux mint是基于Ubuntu的深度改造,所以按照网上针对Ubuntu的安装方法基本都是有用的.LinuxMint自身就携带了IBUS和fcitx两个框架.然而并非每次都能正常使 ...