首页 > 其他 > 详细

CodeForces451B - Sort the Array - 暴力

时间:2020-06-29 23:55:28      阅读:87      评论:0      收藏:0      [点我收藏+]

这题还是B题,1300的,但是我总感觉我思路哪里有问题,代码长度比别人的要多几十行。

#include <iostream>
#include <string.h>
#include <algorithm>
#include <cmath>
#include <map>
using namespace std;
typedef long long ll;

int a[100020],b[100020];

int main()
{
    int n;
    cin>>n;
    int flag=1;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        if(i!=0&&a[i]<a[i-1])
            flag++;
        b[i]=a[i];
    }

    sort(b,b+n);
    int L=1,R=1;
    for(int i=0;i<n;i++)
    {
        if(a[i]!=b[i])
        {
            L=i+1;
            break;
        }
    }
    for(int i=n-1;i>=0;i--)
    {
        if(a[i]!=b[i])
        {
            R=i+1;
            break;
        }
    }
    if(L>R)
    {
        cout<<"no"<<endl;
        return 0;
    }
    int p=R-1;
    flag=0;
    for(int i=L-1;i<=R-1;i++)
    {
        if(a[i]!=b[p--])
        {
            flag=1;
            break;
        }
    }
    if(flag)
        cout<<"no"<<endl;
    else
    {
        cout<<"yes"<<endl;
        cout<<L<<" "<<R<<endl;
    }
    return 0;
}

CodeForces451B - Sort the Array - 暴力

原文:https://www.cnblogs.com/OFSHK/p/13210868.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!