Codeforces 451 B. Sort the Array

简介:

题目链接:http://codeforces.com/contest/451/problem/B

#include <iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef long long LL;
const int maxn=1e5+5;
int a[maxn];
int b[maxn];
int main()
{
    int m,j,k;
    while(cin>>m)
    {
        j=k=0;
        for(int i=0; i<m; i++)
          cin>>a[i],b[i]=a[i];
        sort(b,b+m);
        for(int i=0; i<m; i++)
            if(b[i]!=a[i])
            {
                j=i;
                break;
            }
        for(int i=m-1;  i>=0; i--)
            if(b[i]!=a[i])
            {
                k=i;
                break;
            }
        int sum=0;
        for(int i=j; i<=k; i++)
        {
            if(a[i]==b[k-i+j])
            sum++;
        }
        //cout<<j<<"  "<<k<<"   "<<sum<<endl;
        if(sum == (k-j+1))
            puts("yes"),cout<<j+1<<" "<<k+1<<endl;
        else
            puts("no");
    }
    return 0;
}
目录
相关文章
|
8月前
|
人工智能
codeforces 315 B.Sereja and Array
codeforces 315 B.Sereja and Array
21 0
|
8月前
codeforces 299 A. Ksusha and Array
题目就是让你找出一个数组中可以将这个数组中所有数整除的数,很明显,如果存在,这个数肯定是最小的一个。
29 0
|
Web App开发 JavaScript 前端开发
学习Array类型看这一篇就够了(Array类型特点,Array原型方法,浏览器sort底层实现,深浅拷贝)
学习Array类型看这一篇就够了(Array类型特点,Array原型方法,浏览器sort底层实现,深浅拷贝)
113 0
|
人工智能 C++ Python
LeetCode 905. Sort Array By Parity
LeetCode 905. Sort Array By Parity
75 0
|
Perl
Codeforces 1312E. Array Shrinking(区间DP 栈)
Codeforces 1312E. Array Shrinking(区间DP 栈)
79 0
4.1、Array数组常用的方法(map、push、sort、filter、join、split)
4.1、Array数组常用的方法(map、push、sort、filter、join、split)
117 0
|
人工智能 Windows BI