【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][ ...
随机推荐
- VS2012快捷操作功能
VS2003用了6年,感情深厚,最近换工作刚刚接触VS2010,使用一个月感觉VS2010在人性化方面的功能实在是太强悍了,大大提高了写代码的效率,就如同魔兽世界里的快捷键操作一样,左手抚键右手摸鼠, ...
- 全文检索引擎及工具 Lucene Solr
全文检索引擎及工具 lucence lucence是一个全文检索引擎. lucence代码级别的使用步骤大致如下: 创建文档(org.apache.lucene.document.Document), ...
- OpenCv: 二维坐标的旋转方程
1. 可以写成一个矩阵的形式,也可以写成向量的形式: b 为选转角度加pi/2 x1 = x cos(b) - ysin(b) ; y1 = x sin(b) + y cos(b).
- 使用GitGUI创建上传本地工程
参考链接: 使用Git-GUI创建工程 http://jingyan.baidu.com/article/27fa732683ebf546f8271f2e.html 一.刚创建的github版本库,在 ...
- 使用CImage类 显示图片
在不适用openCv的一种时候,使用CImage显示图片数据,并且直接嵌入DC框中. 使用CImage 在pic控件里显示图片 void CMyCalLawsDlg::MyShowImage( CIm ...
- (转)基于MVC4+EasyUI的Web开发框架经验总结(9)--在Datagrid里面实现外键字段的转义操作
http://www.cnblogs.com/wuhuacong/p/3872890.html 我们在使用EasyUI的时候,很多情况下需要使用到表格控件datagrid,这个控件控件非常强大,使用起 ...
- Combobox 下拉框赋值
string sql = "select distinct RoleName from tb_Role"; DataTable dt = SqlHelper.DataTable(s ...
- apicloud常用分享方法
app中经常会有分享的功能,不管是分享商品还是文字还是图片或者是发送给微信好友扣扣好友,一下做一总结. 分享的样式(分享所有的样式模块):MNActionButton. 在apicloud 中添加这个 ...
- [接口管理平台] eoLinker AMS 专业版 V3.5 :加入数据结构管理、通用函数管理、API 快速测试等近 30 项更新
eoLinker AMS是集API文档管理.API自动化测试.开发协作三位一体的综合API开发管理平台,是中国最大的在线API管理平台.目前eoLinker AMS已经为来自全球的超过两万家企业托管超 ...
- 洛谷P1012 拼数【字符串+排序】
设有nn个正整数(n≤20)(n≤20),将它们联接成一排,组成一个最大的多位整数. 例如:n=3n=3时,33个整数1313,312312,343343联接成的最大整数为:3433121334331 ...