找出一个递减序列,假设有两个或两个以上递减序列直接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. Codeforces.714D.Searching Rectangles(交互 二分)

    题目链接 \(Description\) 在一个\(n*n\)的二维平面中有两个不相交的整点矩形,每次可以询问两个矩形有几个完全在你给出的一个矩形中.200次询问内确定两个矩形坐标. \(Soluti ...

  2. PHP session用redis存储

    redis的官方github这么说: phpredis can be used to store PHP sessions. To do this, configure session.save_ha ...

  3. 20162303 解读同伴的收获&解决同伴的问题 周三补交

    解读同伴的收获&解决同伴的问题 11月29号 解决同伴的问题 我的同组同学是20162307学号张韵琪同学 同组同学的问题是动态规划算法步骤中递归定义的最优值 我理解他的意思是她不太理解最优值 ...

  4. 协议栈中使用crc校验函数

    CRC校验介绍:循环冗余校验码,原理是多项式除法 ZigBee协议栈:能够使zigbee节点相互之间组网,数据传输,数据获取,数据显示 思路以及步骤: 1.因为IAR的程序是用c写的,所以上网查找如何 ...

  5. sgu 194 上下界网络流可行流判定+输出可行流

    #include <cstdio> #include <cstring> #define min(a,b) ((a)<(b)?(a):(b)) #define oo 0x ...

  6. hdu 3949 第k大异或组合

    题意: 给你一些数,其中任选一些数(大于等于一个),那么他们有一个异或和. 求所有这样的异或和的第k小. 我们可以将每一位看成一维,然后就是给我们n个60维的向量,求它们线性组合后得到的向量空间中,第 ...

  7. 读书笔记_Effective_C++_条款三十九:明智而审慎地使用private继承

    private继承的意义在于“be implemented in turns of”,这个与上一条款中说的复合模型的第二层含义是相同的,这也意味着通常我们可以在这两种设计方法之间转换,但书上还是更提倡 ...

  8. ROS知识(12)----cv_bridge依赖opencv版本的问题

    cv_bridge默认依赖的oencv版本是2.4.8,如果安装了新的opencv版本,比如2.4.11,那么在编译cv_bridge时候会提示无法找到opencv 2.4.8.so的库. 为解决这个 ...

  9. android下前端开发诡异bug记录&解决方法

    1.border-radius有bug,围不住background 描述:设置了border-radius后,背景色依然会从圆角里冒出来 解决方法:在设置了border-radius的容器加上back ...

  10. Linux下以特定用户运行命令

    方法汇总: 1.su 2.sudo 3.runuser 比较常用的方式:su 示例:su - root -s /bin/sh -c "/usr/local/nginx/sbin/nginx& ...