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. bzoj千题计划237:bzoj1492: [NOI2007]货币兑换Cash

    http://www.lydsy.com/JudgeOnline/problem.php?id=1492 dp[i] 表示 第i天卖完的最大收益 朴素的dp: 枚举从哪一天买来的在第i天卖掉,或者是不 ...

  2. python scrapy cookies 处理

    def start_requests(self): cookies = 'anonymid=jcokuqwe................省略' # 首先是对cookies进行分割以;为节点 ook ...

  3. [转载]Brackets - 强大免费的开源跨平台Web前端开发工具IDE (HTML/CSS/Javascript代码编辑器)

    http://brackets.io/ Brackets 是一个免费.开源且跨平台的 HTML/CSS/JavaScript 前端 WEB 集成开发环境 (IDE工具).该项目由 Adobe 创建和维 ...

  4. HDU 4502 吉哥系列故事——临时工计划(一维动态规划)

    题意:吉哥的假期是1到n天,然后有m个工作可以让吉哥选择做,每个工作都有一个开始 t_s  和结束的时间   t_e ,都用天来表示,然后每个工作必须从第一天做到最后一天, 从头到尾做完之后就可以得到 ...

  5. 常用的C#编译命令

    使用 csc.exe 实现命令行生成 作为一个半路出家的非计算机专业出身的前端码农,最近对C#很感兴趣,原因如下: 1.希望通过学习C#能熟悉一下windows系统和一些概念,例如:windows服务 ...

  6. C++的那些事 1

    最近在看c++的一些库文件,里面的一些比较陌生但看起来挺有用的一些东西,在此记下,以免日后看到再翻找资料. template <size_t _Nb> 这是在看bitset的时候看到的,之 ...

  7. mysql 当前时间

    1.  mysql 获取当前时间 select now() ,current_timestamp(),localtimestamp(),sysdate() ,curdate(),curtime(),u ...

  8. 安装numpy只需一步简单的方法

    因为最近在搞机器学习,涉及到python,因为我的python版本还是windoes下的2.7版本,在学习K临近算法的时候,需要安装numpy函数,下面就把自己的安装方法写下来 1:登录网址  htt ...

  9. java 轨迹栈

    printStackTrace()方法所提供的信息可以通过getStackTrace()方法直接访问. getStackTrace()方法返回一个由根轨迹中的元素所构成的数组,每一个元素都表示栈中的一 ...

  10. CentOS 6 安装chromium

    由于centos 6对C++11支持不足的缘故,目前chromium已经不再支持CentOS 6系列. 这里介绍如何在centos 6系列安装chromium. 1.添加chromium源 cd /e ...