zoukankan      html  css  js  c++  java
  • CodeForces451B

    这题还是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;
    }
    
  • 相关阅读:
    JavaScript学习笔记之数组(一)
    Ajax与CORS通信
    JSONP跨域
    JavaScript原型与原型链
    CSS布局套路
    爱奇艺的自制节目
    2019.3.6错误经验
    Kickdown UVA
    ASP.NET Web
    C# Windows
  • 原文地址:https://www.cnblogs.com/OFSHK/p/13210868.html
Copyright © 2011-2022 走看看