#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. YouComplete:vim自动补全插件

    在github上下载插件,按照README.md安装 1,ubuntu安装 vim插件管理:vundle插件安装同样按照 README.md 操作 2,user guide General Usage ...

  2. UVA 12563 Jin Ge Jin Qu hao

    dp-背包 开始用普通dp写了一发发现没法确定最大时间... 后来看到大牛机智的写法,嗯...dp表示当前状态能否成立:然后从条件最好的状态开始遍历,直到这个状态成立然后退出遍历. 具体的看代码吧.. ...

  3. UIDatePicker控件

    UIDatePicker继承关系如下: UIDatePicker-->UIControl-->UIView-->UIResponder-->NSObject 1.创建UIDat ...

  4. SQL 查找某个字段的首字母

    执行以下SQL语句 SELECT ,--或得首字母出现的位置 ),--要替换的字符串 ),''),--替换后的结果 OrderId, * FROM dbo.OrderSync 得到结果如下

  5. Delphi Windows API判断文件共享锁定状态(OpenFile和CreateFile两种方法)

    一.概述 锁是操作系统为实现数据共享而提供的一种安全机制,它使得不同的应用程序,不同的计算机之间可以安全有效地共享和交换数据.要保证安全有效地操作共享数据,必须在相应的操作前判断锁的类型,然后才能确定 ...

  6. Python中:self和__init__的含义 + 为何要有self和__init__

    Python中:self和__init__的含义 + 为何要有self和__init__ 背景 回复: 我写的一些Python教程,需要的可以看看 中SongShouJiong的提问: Python中 ...

  7. ASP.NET 4.0升级至ASP.NET 4.5需要注意的地方 【转】

    原以为只要在Visual Studio 2012中将每个项目的Target framework设置为.NET Framewor 4.5进行编译,然后在web.config中设置compilation的 ...

  8. 聚类算法初探(四)K-means

    最近由于工作需要,对聚类算法做了一些相关的调研.现将搜集到的资料和自己对算法的一些理解整理如下,供大家参考. 另外在算法代码方面,我也做了一些实现(包括串行和并行),欢迎感兴趣的朋友探讨和交流. 第一 ...

  9. 【泛化物品】【HDU1712】【ACboy needs your help】

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

  10. Time Out 访问数据库超时处理 .NET

    using System.Reflection; using System.Data.SqlClient; TransactionSelectTableAdapter adapter = new Tr ...