/*
思路:
找到单调下降串的起始位置[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. 博客迁移至CSDN

    本人的技术博客已经迁移至CSDN,地址为http://blog.csdn.net/starrow,现为Lotus Domino开发领域最活跃丰富的博客,内容包括Lotus Domino, JavaSc ...

  2. uva-439

    题意:骑士在一个8*8的棋盘上移动,1-8代表行号,a-h代表列号,给出骑士的初始位置和目的位置,求骑士最少的移动步数:题目隐含一层意思(骑士移动规则是中国象棋的“马”的走法) 输入:一串字符串,包含 ...

  3. linux(centos)源码安装git

    最近使用一个开源库,部署的的时候需要用git克隆依赖库.刚好系统没安装git.就尝试了源码安装git. 源码下载地址:http://codemonkey.org.uk/projects/git-sna ...

  4. 为Apache动态增加模块

    Apache已经安装完毕并投入运行,但是后来却发现部分模块没有加载,当然有两个方法: 1. 一是完全重新编译Apache, 再安装 2. 编译模块为SO文件,使用LoadModule指令加载扩展模块. ...

  5. 定时自动关闭messagebox

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  6. Jquery的multifile使用随记

    1.多文件上传: 2.如上几个验证不重复,和限制上传数量的验证显示的是英文,改成中文文本时,如果不用国标解码,到时候提示框会出现乱码现象.所以一般需要中文显示的时候,我们应该这样做: 拿denied做 ...

  7. MySQL DELETE语句和TRUNCATE TABLE语句的区别

    MySQL DELETE语句和TRUNCATE TABLE语句的区别 2010-10-08 16:05 佚名 互联网 字号:T | T 在MySQL数据库中,DELETE语句和TRUNCATE TAB ...

  8. linux-dns服务器搭建

    1.先查看系统是否安装了bind rpm -qa|grep bind 2.如果没有安装则

  9. MyRocks简介

    RocksDB是facebook基于LevelDB实现的,目前为facebook内部大量业务提供服务.经过facebook大量工作,将RocksDB为MySQL的一个存储引擎移植到MySQL,称之为M ...

  10. Storm-源码分析- Storm中Zookeeper的使用

    在backtype.storm.cluster.clj中, 定义了storm对于Zookeeper的使用   ClusterState 首先定义操作Zookeeper集群的interface (def ...