找出一个递减序列,假设有两个或两个以上递减序列直接no了,然后对递减序列两端数start。end,然后比較a[start]和a[end+1] 。 a[end] 和a[start-1]

#include<iostream>

#include<stdio.h>

using namespace std;

int a[100005];

int main(){

   // freopen("in.txt","r",stdin);

    int n;

    while(~scanf("%d",&n)){

        a[0]=-1;

        a[n+1]=1000000009;

        for(int i=1;i<=n;i++)

            scanf("%d",&a[i]);

        int start=-1,end=-1,flag=0;

        for(int i=2;i<=n+1;i++){

            if(a[i-1]>a[i] && start==-1){

                start=i-1;

            }

            else if(start!=-1 && end==-1 && a[i-1]<a[i]){

                end=i-1;

                flag=1;

            }

            else if(a[i-1]>a[i] && start!=-1 && end!=-1){

                flag=2;

                break;

            }

        }

   //     cout<<"初始位置:"<<start<<" "<<end<<endl;

        if(n==1 || start==end){

            cout<<"yes"<<endl;

            cout<<"1 1"<<endl;

        }

        else if(flag==2){

            cout<<"no"<<endl;

        }

        else if(a[start]<a[end+1] && a[end]>a[start-1]){

            cout<<"yes"<<endl;

            cout<<start<<" "<<end<<endl;

        }

        else

            cout<<"no"<<endl;

    }

}



B - Sort the Array的更多相关文章

  1. CF451B Sort the Array 水题

    Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...

  2. [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序

    11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...

  3. Codeforces Round #258 (Div. 2) . Sort the Array 贪心

    B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...

  4. Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

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

  5. Codeforces Round #258 (Div. 2)——B. Sort the Array

    B. Sort the Array time limit per test 1 second memory limit per test 256 megabytes input standard in ...

  6. [LeetCode] 912. Sort an Array 数组排序

    Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1] Outp ...

  7. LeetCode 912. 排序数组(Sort an Array) 43

    912. 排序数组 912. Sort an Array 题目描述 每日一算法2019/6/15Day 43LeetCode912. Sort an Array

  8. Minimum number of swaps required to sort an array

    https://www.hackerrank.com/challenges/minimum-swaps-2/problem Minimum Swaps II You are given an unor ...

  9. 【leetcode】912. Sort an Array

    题目如下: Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1 ...

  10. 【LeetCode】912. Sort an Array 解题报告(C++)

    作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数排序 桶排序 红黑树排序 归并排序 快速排序 ...

随机推荐

  1. 【堆优化Dijkstra+字典序最短路方案】HDU1385-Minimum Transport Cost

    [题目大意] 给出邻接矩阵以及到达各个点需要付出的代价(起点和终点没有代价),求出从给定起点到终点的最短路,并输出字典序最小的方案. [思路] 在堆优化Dijkstra中,用pre记录前驱.如果新方案 ...

  2. Educational Codeforces Round 13 B. The Same Calendar 水题

    B. The Same Calendar 题目连接: http://www.codeforces.com/contest/678/problem/B Description The girl Tayl ...

  3. Python学习笔记(三):随机生成函数方法

    本文是在Python2下总结! Python中的random模块用于生成随机数,如果想生成随机数需要先导入random的模块然后才能使用其中的方法,下面简单介绍一下常用的结果函数方法: 1·.rand ...

  4. 关于maven依赖中的<scope>provided</scope>使用

    今天开发web的时候,需要用到servlet-api,于是在pom.xml中添加依赖 <dependency> <groupId>javax.servlet</group ...

  5. ECCV 2014 Results (16 Jun, 2014) 结果已出

    Accepted Papers     Title Primary Subject Area ID 3D computer vision 93 UPnP: An optimal O(n) soluti ...

  6. Rete算法

    RETE算法介绍一. rete概述Rete算法是一种前向规则快速匹配算法,其匹配速度与规则数目无关.Rete是拉丁文,对应英文是net,也就是网络.Rete算法通过形成一个rete网络进行模式匹配,利 ...

  7. 安装openldap

    在Mac OS X下安装 Mac OS X 下默认安装了openldap,我们只需要配置就可以. 1. 在/etc/openldap 下创建slapd.conf 文件(只需copy slapd.con ...

  8. iOS开发中的 ARC

    1. weak属性(弱引用) 被weak修饰的对象叫弱引用,不算对象持有者,一个方法执行完后会导致这个对象自动释放掉,并将对象的指针设置成nil,我使用GCD延时1000ms来验证,1000ms之后, ...

  9. ubuntu上minigui调试环境的建立

    minigui一共有两个版本:商业版()和GPL版(),问了一下飞漫软件,使用商业版前期的费用是9万,有技术支持,包括5000个licenses的费用,后期10K的量的话,每个licenses要6块, ...

  10. 基于CXF框架下的SOAP Webservice服务端接口开发

    最近对webservice 进行入门学习,网上也是找了很多的学习资料.总得感觉就是这了解点,那了解点.感觉不够系统,不够容易入门.差不多断断续续看了一个星期了,今天小有成果,把客户端,服务端都搞定了. ...