Codeforces_451_B

http://codeforces.com/problemset/problem/451/B

取前后第一个不满足条件的位置,逆序,判断。

#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;

int main()
{
    int n,a[100005],left = 1,right = 1;
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
        cin >> a[i];
    }
    for(int i = 1;i <= n-1;i++)
    {
        if(a[i] > a[i+1])
        {
            left = i;
            break;
        }
    }
    for(int i = n;i > 0;i--)
    {
        if(a[i] < a[i-1])
        {
            right = i;
            break;
        }
    }
    reverse(a+left,a+right+1);
    int flag = 1;
    for(int i = 1;i <= n-1;i++)
    {
        if(a[i] > a[i+1])
        {
            flag = 0;
            break;
        }
    }
    if(flag)
    {
        printf("yes\n");
        printf("%d %d\n",left,right);
    }
    else
    {
        printf("no\n");
    }
    return 0;
}
时间: 2024-11-07 22:36:18

Codeforces_451_B的相关文章