#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <set>
#include <map>
using namespace std; const int maxn=; struct point
{
int x, y;
}; int n;
int sum;
int a[maxn], des[maxn];
point ans[]; void init()
{
scanf("%d", &n);
a[]=; a[n+]=n+;
for (int i=; i<=n; ++i) scanf("%d", &a[i]);
}
void rev(int le, int ri)
{
for (int i=le; i<=(ri+le)/; ++i)
swap(a[i], a[ri-(i-le)]);
}
bool check()
{
for (int i=; i<=n; ++i)
if (a[i]!=i) return false;
return true;
}
void print(int step)
{
printf("%d\n", step);
for (int i=step; i>; --i)
printf("%d %d\n", ans[i].x, ans[i].y);
exit();
}
void dfs(int k)
{
if (check()) print(k-);
if (k>) return;
for (int i=; i<n; ++i)
for (int j=i+; j<=n; ++j)
if (abs(a[i-]-a[j])== || abs(a[i]-a[j+])==)
{
ans[k].x=i;
ans[k].y=j;
rev(i, j);
dfs(k+);
rev(i, j);
}
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
init();
dfs();
return ;
}

Codeforces 339E的更多相关文章

  1. python爬虫学习(5) —— 扒一下codeforces题面

    上一次我们拿学校的URP做了个小小的demo.... 其实我们还可以把每个学生的证件照爬下来做成一个证件照校花校草评比 另外也可以写一个物理实验自动选课... 但是出于多种原因,,还是绕开这些敏感话题 ...

  2. 【Codeforces 738D】Sea Battle(贪心)

    http://codeforces.com/contest/738/problem/D Galya is playing one-dimensional Sea Battle on a 1 × n g ...

  3. 【Codeforces 738C】Road to Cinema

    http://codeforces.com/contest/738/problem/C Vasya is currently at a car rental service, and he wants ...

  4. 【Codeforces 738A】Interview with Oleg

    http://codeforces.com/contest/738/problem/A Polycarp has interviewed Oleg and has written the interv ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. CodeForces - 274B Zero Tree

    http://codeforces.com/problemset/problem/274/B 题目大意: 给定你一颗树,每个点上有权值. 现在你每次取出这颗树的一颗子树(即点集和边集均是原图的子集的连 ...

  7. CodeForces - 261B Maxim and Restaurant

    http://codeforces.com/problemset/problem/261/B 题目大意:给定n个数a1-an(n<=50,ai<=50),随机打乱后,记Si=a1+a2+a ...

  8. CodeForces - 696B Puzzles

    http://codeforces.com/problemset/problem/696/B 题目大意: 这是一颗有n个点的树,你从根开始游走,每当你第一次到达一个点时,把这个点的权记为(你已经到过不 ...

  9. CodeForces - 148D Bag of mice

    http://codeforces.com/problemset/problem/148/D 题目大意: 原来袋子里有w只白鼠和b只黑鼠 龙和王妃轮流从袋子里抓老鼠.谁先抓到白色老鼠谁就赢. 王妃每次 ...

随机推荐

  1. ACboy needs your help again!--hdu1702

    ACboy needs your help again! Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ( ...

  2. A+B II

    Problem Description I have a very simple problem for you. Given two integers A and B, your job is to ...

  3. Qt creator error: LNK1123: 转换到 COFF 期间失败: 文件无效或损坏(vs2010的嵌入式清单文件)

    下面是vs2010导入别人文件时出现的问题的解决方案:VS2010在经历一些更新后,建立Win32 Console Project时会出“error LNK1123” 错误,解决方案为将 项目|项目属 ...

  4. C语言的本质(14)——不完全类型和复杂声明

    ISO 将 C 的类型分为三个不同的集合: 函数.对象和不完全类型三大类.函数类型很明显:对象类型包含其他一切,除非不知道对象的大小.该标准使用术语"对象类型"指定指派的对象必须具 ...

  5. JqueryeasyUI选项卡选择判定更改内部Iframe地址

    1.tabs的常用操作 //1.判断tab是否存在. var currtab = $('#tabs').tabs('getSelected'); //2.判断点击的tab是否是当前选中的tab. va ...

  6. linux之SQL语句简明教程---主键,外来键

    主键 (Primary Key) 中的每一笔资料都是表格中的唯一值.换言之,它是用来独一无二地确认一个表格中的每一行资料.主键可以是原本资料内的一个栏位,或是一个人造栏位 (与原本资料没有关系的栏位) ...

  7. poj 1573 Robot Motion_模拟

    又是被自己的方向搞混了 题意:走出去和遇到之前走过的就输出. #include <cstdlib> #include <iostream> #include<cstdio ...

  8. redi中删除所有的数据

    EVAL "return redis.call('del', unpack(redis.call('keys', ARGV[1])))" 0 *

  9. Nginx学习——http配置项解析编程

    http配置项解析编程 配置config ngx_addon_name=ngx_http_mytest_module HTTP_MODULES="$HTTP_MODULES ngx_http ...

  10. 启动监听报错:TNS-12537: TNS:connection closed TNS-12560: TNS:protocol adapter error TNS-00507: Connection closed Linux Error: 29: Illegal seek

    启动监听程序报错: 说明:在rhel5.8上安装完成oracle11g数据库后,使用netca创建完监听,启动监听时报错.还未使用dbca创建实例. [oracle@rusky-oracle11g ~ ...