【POJ 2286】 The Rotation Game
【题目链接】
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的更多相关文章
- 【POJ 2482】 Stars in Your Window(线段树+离散化+扫描线)
[POJ 2482] Stars in Your Window(线段树+离散化+扫描线) Time Limit: 1000MS Memory Limit: 65536K Total Submiss ...
- bzoj 2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MB Description ftiasch是个十分受女生欢迎的同学,所以 ...
- 【链表】BZOJ 2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 382 Solved: 111[Submit][S ...
- BZOJ2288: 【POJ Challenge】生日礼物
2288: [POJ Challenge]生日礼物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 284 Solved: 82[Submit][St ...
- BZOJ2293: 【POJ Challenge】吉他英雄
2293: [POJ Challenge]吉他英雄 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 80 Solved: 59[Submit][Stat ...
- BZOJ2287: 【POJ Challenge】消失之物
2287: [POJ Challenge]消失之物 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 254 Solved: 140[Submit][S ...
- BZOJ2295: 【POJ Challenge】我爱你啊
2295: [POJ Challenge]我爱你啊 Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 126 Solved: 90[Submit][Sta ...
- BZOJ2296: 【POJ Challenge】随机种子
2296: [POJ Challenge]随机种子 Time Limit: 1 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 114 Solv ...
- BZOJ2292: 【POJ Challenge 】永远挑战
2292: [POJ Challenge ]永远挑战 Time Limit: 10 Sec Memory Limit: 128 MBSubmit: 513 Solved: 201[Submit][ ...
随机推荐
- Vue蚂蜂窝Vue-cli+webpack做的
先来看下效果 项目地址 喜欢star一下哦
- js点击事件 注册下一步实现代码
点击事件: <body> <input type="button" id="btn1"/> <input type="b ...
- 【Oracle】redo与undo
一 .redo(重做信息) 是Oracle在线(或归档)重做日志文件中记录的信息,万一出现失败时可以利用这些数据来“重放”(或重做)事务.Oracle中记录这些信息的文件叫做redo log file ...
- [CefSharp] 如何在JavaScript中调用C#代码
本例在WinForms下实现,具体流程与WPF一致. 本例仅供调用示例,不代表正常业务书写流程. 1. 创建WinForms项目,并将项目属性设置为x86平台 此处预先设置,避免引用时报错,再花更多的 ...
- 据说现在很缺设计师,阿里云的LOGO是用键盘打出来的……
今天,阿里云发布了自己的新LOGO,官方的解读是:“[]”这个呢其实是代码中常用的一个符号,代表着计算:中间的“—”则代表流动的数据.在官网等平台上,阿里云新LOGO是动态的,中间的“—”会匀速移动, ...
- 【sqli-labs】 less1 GET - Error based - Single quotes - String(GET型基于错误的单引号字符型注入)
GET方式提交id参数 添加单引号,出现报错,爆出数据库名称和部分SQL语句 http://localhost/sqli/Less-1/?id=1' 使用order by猜测字段数,用#注释掉后面li ...
- c#动态类型Dynamic
需引用System.Dynamic命名空间 来源:http://www.cnblogs.com/ryanding/archive/2010/12/09/1900106.html dynamic Cus ...
- Scala语言学习笔记——方法、函数及异常
1.Scala 方法及函数区别 ① Scala 有方法与函数,二者在语义上的区别很小.Scala 方法是类的一部分,而函数是一个对象可以赋值给一个变量.换句话来说在类中定义的函数即是方法 ② Scal ...
- python 从Excel中取值
import openpyxl from openpyxl import load_workbook def open_file(file_path): workbook = load_workboo ...
- hadoop中的job.setOutputKeyClass与job.setMapOutputKeyClass
初学mr时,觉得没什么,但是学了一段时间,重新复习时发现程序中mr程序中一般都会有 hadoop中的job.setOutputKeyClass(theClass)与job.setOutputValue ...