/*
思路:
找到单调下降串的起始位置[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. ok

    第一个姑娘该是个爱你的人,出现在你没法区分爱和饥渴的时候.那时候你还在青春期的尾巴上,满脑子的性冲动混合着韩剧爱情幻想.你自尊脆弱而又怯懦无助,随便抓住哪一根稻草都当是救命的灵药. 她也许相貌平平,但 ...

  2. iOS开发零基础--Swift教程 可选类型

    可选类型的介绍 注意: 可选类型时swift中较难理解的一个知识点 暂时先了解,多利用Xcode的提示来使用 随着学习的深入,慢慢理解其中的原理和好处 概念: 在OC开发中,如果一个变量暂停不使用,可 ...

  3. vb小菜一枚-----了解“类型推理”

    局部类型推理 (Visual Basic) Visual Studio 2013   其他版本   Visual Basic 编译器使用类型推理来确定未使用 As 子句声明的局部变量的数据类型. 编译 ...

  4. php下xcache的安装

    下载xcache: wget http://xcache.lighttpd.net/pub/Releases/3.2.0/xcache-3.2.0.tar.gz 安装: tar zxvf xcache ...

  5. 据说练就了一指禅神功的觅闻实时手机新闻网,正以每天2000+IP的用户量递增。有智能手机的可以当场进行体验,没有的就算了哈

    据说练就了一指禅神功的觅闻实时手机新闻网,正以每天2000+IP的用户量递增.有智能手机的可以当场进行体验,没有的就算了哈 觅闻实时手机新闻网  http://m.yunxunmi.com 在IOS. ...

  6. 免费的HTML5版uploadify送上

    相信有不少同学用过uploadify这一款文件上传插件,它支持多文件选择.能显示进度条.可配置性高,总体来说是比较好用的.官网有两个版本供下载,分别是flash版和HTML5版.不过令人惋惜的是,HT ...

  7. [.net 面向对象编程基础] (17) 数组与集合

    [.net 面向对象编程基础] (17) 数组与集合 学习了前面的C#三大特性,及接口,抽象类这些相对抽象的东西以后,是不是有点很累的感觉.具体的东西总是容易理解,因此我们在介绍前面抽象概念的时候,总 ...

  8. Kinect for Windows SDK 1.8的改进及新特性

    今年3月, 微软推出了Kinect for Windows SDK 1.7 更新,包括了手势识别 Kinect Interactions 和实时 3D 建模 Kinect Fusion 两项新技术. ...

  9. Linux cat命令

    200 ? "200px" : this.width)!important;} --> 介绍 cat命令经常会用来查看一个文件的内容,并且结合它本身的一些参数经常可以用来做一 ...

  10. Linux网络编程系列-套接口选项控制

    获取和设置套接口选项的方法有: getsockopt/setsockopt fcntl ioctl getsockopt/setsockopt 这两个函数仅用于套接口(socket)的设置,另外两个函 ...