B. Sort the Array

题目连接:

http://codeforces.com/contest/451/problem/B

Description

Being a programmer, you like arrays a lot. For your birthday, your friends have given you an array a consisting of n distinct integers.

Unfortunately, the size of a is too small. You want a bigger array! Your friends agree to give you a bigger array, but only if you are able to answer the following question correctly: is it possible to sort the array a (in increasing order) by reversing exactly one segment of a? See definitions of segment and reversing in the notes.

Input

The first line of the input contains an integer n (1 ≤ n ≤ 105) — the size of array a.

The second line contains n distinct space-separated integers: a[1], a[2], ..., a[n] (1 ≤ a[i] ≤ 109).

Output

Print "yes" or "no" (without quotes), depending on the answer.

If your answer is "yes", then also print two space-separated integers denoting start and end (start must not be greater than end) indices of the segment to be reversed. If there are multiple ways of selecting these indices, print any of them.

Sample Input

3

3 2 1

Sample Output

yes

1 3

Hint

题意

给你n个数,然后你可以交换一个子串的顺序,问你能不能使得这n个数是单调递增的。

题解:

贪心去交换就好了,交换完再check一下就行。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5+7;
int n;
int a[maxn];
bool check()
{
for(int i=2;i<=n;i++)
if(a[i]<a[i-1])return false;
return true;
}
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
for(int i=1;i<=n;i++)
{
int j=i+1;
for(;j<=n;j++)
if(a[j]>=a[i])
break;
if(j!=i+1)
{
reverse(a+i,a+j);
if(check())
{
printf("yes\n");
printf("%d %d",i,j-1);
}
else
printf("no\n");
return 0;
}
}
if(check())
{
printf("yes\n");
printf("%d %d",1,1);
}
else
printf("no\n");
}

Codeforces Round #258 (Div. 2) . Sort the Array 贪心的更多相关文章

  1. Codeforces Round #555 (Div. 3) E. Minimum Array (贪心,二分,set)

    题意:给你两个长度为\(n\)的数组\(a\)和\(b\),元素值在\([0,n-1]\),可以对\(b\)数组的元素任意排序,求新数组\(c\),满足\(c_i=(a_i+b_i)\ mod\ n\ ...

  2. Codeforces Round #258 (Div. 2)[ABCD]

    Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...

  3. Codeforces Round #258 (Div. 2) 小结

    A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...

  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. Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array

    解题报告 http://blog.csdn.net/juncoder/article/details/38102391 对于给定的数组,取对数组中的一段进行翻转,问翻转后是否是递增有序的. 思路: 仅 ...

  7. Codeforces Round #258 (Div. 2)

    A - Game With Sticks 题目的意思: n个水平条,m个竖直条,组成网格,每次删除交点所在的行和列,两个人轮流删除,直到最后没有交点为止,最后不能再删除的人将输掉 解题思路: 每次删除 ...

  8. Codeforces Round #258 (Div. 2)(A,B,C,D)

    题目链接 A. Game With Sticks time limit per test:1 secondmemory limit per test:256 megabytesinput:standa ...

  9. Codeforces Round #258 (Div. 2)-(A,B,C,D,E)

    http://blog.csdn.net/rowanhaoa/article/details/38116713 A:Game With Sticks 水题.. . 每次操作,都会拿走一个横行,一个竖行 ...

随机推荐

  1. ubuntu中mysql中文乱码及用python3.x调用

    首先声明解决方法也是网上找来的,知识自己记下来以防以后用到.   ubuntu版本是14.04使用apt-get命令安装mysql sudo apt-get install mysql-server ...

  2. ASP.NET生成二维码

    下面使用ThoughtWorks.QRCode.dll这个类库,实现生成二维码 使用时需要增加:下面三个命名空间 using ThoughtWorks.QRCode.Codec; using Thou ...

  3. oracle的中文排序问题

    mysql中文排序有convert(name using gbk)这样的函数,于是研究了一下oracle中文排序: 使用拼音排序 SQL> select * from chineseordert ...

  4. Hibernate5总结

    1. 明确Hibernate是一个实现了ORM思想的框架,它封装了JDBC,是程序员可以用对象编程思想来操作数据库. 2. 明确ORM(对象关系映射)是一种思想,JPA(Java Persistenc ...

  5. slf4j MDC使用

    slf4j MDC使用 最近也是在项目代码里发现一个地方有个MDC.put(),忍不住好奇点了进去,于是知道了MDC这个东西,细研究一下,发现还真是个好东西. MDC解决了什么问题 MDC全名Mapp ...

  6. 记一次ThreadPoolExecutor面试

    ThreadPoolExecutor点滴 线程池应该也是面试绕不开的一个点,平时大家也没少用,但其实也有一些小Tips还是值得记录一下. Constructor public ThreadPoolEx ...

  7. 记一次HashMap面试

    记一次HashMap面试 从网上已经身边同事朋友的面试情况来看,面试HashMap几乎是必问的,网上也很多类似的文章,但是真面起来,发现还是有很多点可以深抠的.本篇就结合一次面试经历说一下之前没有注意 ...

  8. linux网桥浅析

    linux网桥浅析 原文链接:http://hi.baidu.com/_kouu/item/25787d38efec56637c034bd0 什么是桥接?简单来说,桥接就是把一台机器上的若干个网络接口 ...

  9. MySql 死锁时的一种解决办法【转】

    转自:http://blog.csdn.net/mchdba/article/details/38313881 之前也遇到一次,今天又遇到了这个问题,所以这次必须解决,网上找到这篇文章帮了大忙,方便以 ...

  10. excel 2016 for mac破解

    1: 首先去官网下载一个正版的: 2:再下载一个破解工具: 链接: http://pan.baidu.com/s/1i4AFHFf 密码: 3yf8 3:最后按照破解教程破解: http://jing ...