/*
思路:
找到单调下降串的起始位置[l, r]
如果左边 0...l-1中的最大值 > l...r中的最小值 或者
r+1...n中的最小值 < l...r中的最大值 都是不能实现排序的!
*/
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long LL;
int cur, nt;
int cnt;
int num[];
int main(){
int i, n;
int begin, end;
int flag;
int min1, max2;
while(scanf("%d", &n)!=EOF){
cnt=cur=;
flag=;
for(i=; i<=n; ++i){
scanf("%d", &nt);
num[i]=nt;
if(nt>cur)
flag=;
if(!flag && nt<cur){
++cnt;
flag=;
begin=i-;
end=i;
}
if(flag && nt<cur)
end=i;
cur=nt;
}
if(cnt==){
min1=0x3f3f3f3f;
if(end!=n)
min1=num[end+];
max2=-0x3f3f3f3f;
if(begin!=)
max2=num[begin-];
if(max2>num[end] || min1<num[begin])
printf("no\n");
else
printf("yes\n%d %d\n", begin, end);
}
else if(cnt==)
printf("yes\n1 1\n");
else printf("no\n");
}
return ;
}
 /*
思路:
将两边单调递增的序列排除(将元素和元素下标一一映射起来,排序之后找到元素和下标映射不同的两个端点),然后中间的那部分就是要翻转的!
最后检查翻转部分的元素和下标是否对应! */
#include<iostream>
#include<algorithm>
#include<map>
#include<cstdio>
#define M 100005
using namespace std;
int n;
int a[M], b[M];
map<int, int>mp;
int main(){
int i;
while(cin>>n){
for(i=; i<n; ++i){
cin>>a[i];
b[i]=a[i];
}
sort(a, a+n);
for(i=; i<n; ++i)
mp[b[i]]=i;
for(i=; i<n; ++i)
a[i]=mp[a[i]];
int L=-, R=-;
for(i=; i<n; ++i)
if(a[i]!=i){
L=i;
break;
}
for(i=n-; i>=; --i)
if(a[i]!=i){
R=i;
break;
}
int ok=;
if(L==- || R==-)
cout<<"yes"<<endl<<"1 1"<<endl;
else{
reverse(a+L, a+R+); for(i=L; i<=R; ++i){
if(a[i]!=i){
ok=;
cout<<"no"<<endl;
break;
}
} if(ok)
cout<<"yes"<<endl<<L+<<" "<<R+<<endl;
}
}
return ;
}

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. 关于合并“.a”文件时遇到的问题

    今天在给工程添加百度地图SDK时,涉及到百度地图的模拟器与真机环境下的.a文件的合并,在使用终端进行 合并时,出现: xcrun: error: active developer path (&quo ...

  2. Codeforces 13C(DP)

    题意:给出一个数列长度小于5000,每次操作将数列中的数加1或减1,问最少需要多少步操作可以得到一个不降序列: 分析:可知最少的次数,一定是由原来的数据构成的(据说可以用反证法证),即有原来的数组成的 ...

  3. HDOJ 4749 Parade Show

    说实在的在比赛时看错了题意,一直对最后一段的描述不是很清楚.闲话少说: 题意:给一个主串,再一个副串,问主串中有多少个子串和副串的的规律相同,即相邻的相等大于小于,用过的就不能再用了. #includ ...

  4. Alamofire源码学习

    Core文件夹:          Alamofire.swift - - - 该文件中主要是给用户提供一些便利的调用方法,用户可以直接调用该文件中的便利方法来使用Alamofire相关功能.     ...

  5. 运维自动化工具---Puppet

    案例环境:-----------------------------------------------------------------主机  操作系统   IP地址  主要软件--------- ...

  6. Android--Alarm机制

    1.Alarm 能够实现 Android 中的定时任务,它与 Java 中的 Timer类的区别在于,Android 系统在休眠状态下时 Timer 类中的定时任务可能无法正常运行,而 Alarm 机 ...

  7. 关于STM32-MDK中preprocessor symbols解释

    preprocessor symbols 是预处理符号的意思,这里相当于宏定义,我们在使用STM32固件库时,由于固件库里面包含的是ST整个系列单片机的定义,如下图 这时在define框中可以作为一个 ...

  8. linux Makefile编写的整理

    最近将Makefile的编写进行了整理和提炼了一下,大致分为五个步骤: 编译总共为五个部分 1.设置编译环境 set compile environment 2.获取要编译的源文件,以及把源文件转换为 ...

  9. 一个简单的python线程池框架

    初学python,实现了一个简单的线程池框架,线程池中除Wokers(工作线程)外,还单独创建了一个日志线程,用于日志的输出.线程间采用Queue方式进行通信. 代码如下:(不足之处,还请高手指正) ...

  10. storysnail的Windows串口编程笔记

    storysnail的Windows串口编程笔记 作者 He YiJun – storysnail<at>gmail.com 团队 ls 版权 转载请保留本声明! 本文档包含的原创代码根据 ...