/*
思路:
找到单调下降串的起始位置[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. 深入浅出C#中的静态与非静态

    C#语言静态类 vs 普通类  C#语言静态类与普通类的区别有以下几点: 1)C#语言静态类无法实例化而普通类可以: 2)C#语言静态类只能从System.Object基类继承:普通可以继承其它任何非 ...

  2. linux中sed的用法【转】

    sed命令行格式为:         sed [-nefri]  ‘command’  输入文本/文件 常用选项:        -n∶取消默认的输出,使用安静(silent)模式.在一般 sed 的 ...

  3. sql 动态语句

    如果动态语句有表变量 例子如下: declare @mS varchar(10) declare @mE varchar(10) declare @mSQL nvarchar(500) --SQL语句 ...

  4. 影响Java EE性能的十大问题(转)

    本文作者是一名有10多年经验的高级系统架构师,他的主要专业领域是Java EE.中间件和JVM技术.他在性能优化和提升方面也有很深刻的见解,下面他将和大家分享一下常见的10个影响Java EE性能问题 ...

  5. mongoDB研究笔记:分片集群的工作机制

    上面的(http://www.cnblogs.com/guoyuanwei/p/3565088.html)介绍了部署了一个默认的分片集群,对mongoDB的分片集群有了大概的认识,到目前为止我们还没有 ...

  6. 图解集合5:不正确地使用HashMap引发死循环及元素丢失

    问题引出 前一篇文章讲解了HashMap的实现原理,讲到了HashMap不是线程安全的.那么HashMap在多线程环境下又会有什么问题呢? 几个月前,公司项目的一个模块在线上运行的时候出现了死循环,死 ...

  7. 作业三(代码规范、代码复审、PSP)

    1.代码规范: 我支持代码要有规范,理由如下. (1).艺术是一个很带有个人风格的学科,天马行空才能凸显出自己的价值.但不要忘了,会艺术的不是生下来就会艺术, 他也需要按照前辈的步骤一步一步的学习基础 ...

  8. ECMAScript 6 简介

    ECMAScript 6 是JavaScript的下一个标准,正处在快速开发之中,大部分已经完成了,预计将在2014年正式发布.Mozilla将在这个标准的基础上,推出JavaScript 2.0. ...

  9. ECMAScript 6中的let和const关键词

    ECMAScript 6中多了两个定义变量的关键词,一个是let,另一个是const,后者顾名思义就是常量定义,前者的作用域范围是块级的. 一般写过js的童鞋都知道,同其他语言一样,JS中的变量作用域 ...

  10. (小常识)Dictionary的遍历

                Dictionary<int, string> objDictionary = new Dictionary<int, string>();       ...