【POJ 3460】 Booksort
【题目链接】
http://poj.org/problem?id=3460
【算法】
IDA*
注意特判答案为0的情况
【代码】
#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; int i,j,n,step,T;
int a[],b[]; inline bool check()
{
int i;
for (i = ; i <= n; i++)
{
if (b[i] != i)
return false;
}
return true;
}
inline int calc()
{
int i,ret = ;
for (i = ; i <= n; i++)
{
if (b[i] != b[i-] + )
ret++;
}
return (ret - ) / + ;
}
inline bool dfs(int dep)
{
int i,j,k,l;
int tmp[];
if (dep == step)
{
if (check())
return true;
}
if (dep + calc() > step) return false;
for (i = ; i <= n - ; i++)
{
for (j = ; j <= n - i; j++)
{
for (k = i + j; k <= n + ; k++)
{
for (l = ; l <= n; l++) tmp[l] = b[l];
for (l = i + j; l < k; l++) b[i+l-i-j] = tmp[l];
for (l = k - j; l < k; l++) b[l] = tmp[l-k+i+j];
if (dfs(dep+)) return true;
for (l = ; l <= n; l++) b[l] = tmp[l];
}
}
}
return false;
} int main()
{ scanf("%d",&T);
while (T--)
{
scanf("%d",&n);
for (i = ; i <= n; i++) scanf("%d",&a[i]);
for (i = ; i <= ; i++)
{
step = i;
for (j = ; j <= n; j++) b[j] = a[j];
if (dfs())
{
printf("%d\n",step);
break;
} else step = ;
}
if (step == ) printf("5 or more\n");
} return ; }
【POJ 3460】 Booksort的更多相关文章
- 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][ ...
- 【POJ 1125】Stockbroker Grapevine
id=1125">[POJ 1125]Stockbroker Grapevine 最短路 只是这题数据非常水. . 主要想大牛们试试南阳OJ同题 链接例如以下: http://acm. ...
随机推荐
- HTML CSS, JavaScript 计算器
效果图: 代码: <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> < ...
- 关于类似vue-cli 脚手架
#!/usr/bin/env node const download = require('download-git-repo') const program = require('commander ...
- JS高级——词法作用域
作用域 1.js中没有块级作用域 2.如果有块级作用域,那么下面代码将会是undefined undefined <script> for (var i = 0; i < 10; i ...
- 1.CentOS安装Redis
首要条件:安装VMware,在虚拟机中安装CentOS. 第一次接触CentOS的开发者最好是在虚拟机手动一步步进行安装,并且系统环境选择开发环境,这样可以避免后期自己要安装诸多运行库. 安装步骤: ...
- 【sqli-labs】 less56 GET -Challenge -Union -14 queries allowed -Variation3 (GET型 挑战 联合查询 只允许14次查询 变化3)
单引号括号闭合 http://192.168.136.128/sqli-labs-master/Less-56/?id=1')%23 http://192.168.136.128/sqli-labs- ...
- seam的定时轮巡
青岛的项目要做一个功能,每天凌晨2点的时候保存一次设备数据,这个就要求项目能够间隔24小时每天去做这个事,是一个自主轮巡. seam框架正好提供了这个功能,@Expiration指定开始时间,@Int ...
- CAD处理键盘被按下事件(com接口VB语言)
主要用到函数说明: MxDrawXCustomEvent::KeyDown 键盘被按下,详细说明如下: 参数 说明 LONG lVk 是按钮码,如F8,的值为#define VK_F8 0x77 返回 ...
- MVC Ajax调用Action时-OnActionExecuting RedirectResult 无法跳转的处理办法
public class BaseController : Controller { protected override void OnActionExecuting(ActionExecuting ...
- 【python】详解numpy库与pandas库axis=0,axis= 1轴的用法
对数据进行操作时,经常需要在横轴方向或者数轴方向对数据进行操作,这时需要设定参数axis的值: axis = 0 代表对横轴操作,也就是第0轴: axis = 1 代表对纵轴操作,也就是第1轴: nu ...
- Django - 基于orm实现用户增删改查
1.基于orm实现用户新增 user_info.html中,增加代码: views.py中,在原user_info函数中,增加判断代码: 备注:最后一句,可以通过return redirect 实现, ...