#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. Code repo

    http://www.oschina.net/news/15806/20-opensource-host-websites/

  2. QtWaitingSpinner

    https://github.com/snowwlex/QtWaitingSpinner

  3. sqlprofiler 常用调试方法

  4. hdu 1536 S-Nim_求sg值模版

    题意:给你很n堆石头,k代表你有k种拿法,然后给出没堆石头的数量,求胜负 直接套用模版 找了好久之前写的代码贴上来 #include<iostream> #include<algor ...

  5. yum cannot retrieve metalink for repository

    Error: Cannot retrieve metalink for repository: epel. Please verify its path and try again

  6. leetcode Permutation

    Given a collection of numbers, return all possible permutations. For example,[1,2,3] have the follow ...

  7. ubuntu登陆后一闪回到登陆界面

    ubuntu登陆后一闪回到登陆界面   最后发现居然是我的环境变量配置问题........   解决方法:   先CTRL+ALT+F1   root进去, 查看nickleo用户为什么登录失败 ca ...

  8. error LNK1104: 无法打开文件“libboost_thread-vc140-mt-gd-1_61.lib”

    error LNK1104: 无法打开文件“libboost_thread-vc140-mt-gd-1_61.lib” 调试->你的项目属性 配置属性->VC++目录 包含目录 D:\bo ...

  9. node.async.auto

    资料 GITHUB async ASYNC详解—from csdn nodejs的高性能与灵活性让服务端开发变得有了些乐趣,最近在看nodejs在服务端的一些应用,觉得其npm下的众多开源包让其虽没有 ...

  10. ROS Node/Topic/Message/Service的一些问题

    1.Node http://blog.exbot.net/archives/1412 (摘自老王说ros) node干的什么活?callback queue里的活.这个callback queue里的 ...