Topic Source: Http://codeforces.com/problemset/problem/451/B
Question: That is to give you a sequence, you can only flip a paragraph in this sequence, ask if you only flip one of the paragraphs, so that the sequence into ascending sequence
Parsing: Find the first one that is not in position after you go, find the first one that does not match, and then flip the paragraph to determine if the result is an ascending sequence
#include <bits / stdc ++. h>
using namespace std;
const int maxn = 1e5 + 1000;
int a [maxn];
int main (void)
{
int n;
cin >> n;
for (int i = 0; i <n; i ++)
scanf ("% d", & a [i]);
int flag = 0;
int l = 0, r = 0;
for (int i = 0; i <n-1; i ++)
{
if (a [i]> a [i + 1])
{
l = i;
break;
}
}
for (int i = n-1; i> = 1; i--)
{
if (a [i] <a [i-1])
{
r = i;
break;
}
}
// reverse flip array
reverse (a + l, a + r + 1);
for (int i = 0; i <n-1; i ++)
{
if (a [i]> a [i + 1])
{
flag = 1;
break;
}
}
if (flag)
puts ("no");
else
{
puts ("yes");
printf ("% d% d \ n", l + 1, r + 1);
}
return 0;
}