题目链接:http://codeforces.com/contest/451/problem/B

思路:首先找下降段的个数,假设下降段是大于等于2的,那么就直接输出no,假设下降段的个数为1,那么就把下降段的起始位置和结束位置记录下来然后进行推断,在进行推断时,有几种特殊情况:(s表示起始位置,e表示结束位置)

1.当e==n&&s!=1时,满足a[n]>a[s-1]输出yes;

2当s==1&&==n时,满足a[1]<a[e+1] 输出yes;

3当s==1&&e==n时,直接输出yes;

4当s!=1&&e!=n时,满足(a[s]<a[e+1])&&(a[e]>a[s-1])时,输出yes

code:

#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm> using namespace std; int a[100010];
int main()
{
int n;
while(scanf("%d",&n)==1)
{
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
}
int flag=1,flag1=1; //用flag记录下降段的个数,这儿我们默认至少有一个下降段
int s=1,e=1;
for(int i=2;i<=n;i++)
{
//printf("AAA%d\n",i);
if(flag==1) //
{
if(a[i-1]>a[i])
{
if(flag1==1) //记录第一个下降段的起始位置
{
flag1=2;
s=i-1;
}
if(i==n) //记录第一个下降段的结束位置
{
e=n;
}
}
if(flag1==2) //推断在第一个下降段结束时,并把flag++;
{
if(a[i-1]<a[i])
{
e=i-1;
flag++;
}
} }
if(flag==2) //假设有第二个下降段,那么就直接输出
{
if(a[i-1]>a[i])
{
flag++;
//printf("AAA%d %d\n",s,e);
printf("no\n");
break;
}
}
}
if(flag==2||flag==1) //对各种情况进行推断
{
if(s==1&&e!=n) //情况1
{
if(a[1]<a[e+1])
{
printf("yes\n%d %d\n",s,e);
}
else
{
printf("no\n");
}
}
else if(e==n&&s!=1) //情况2
{
if(a[n]>a[s-1])
{
printf("yes\n%d %d\n",s,e);
}
else
{
printf("no\n");
}
}
else if(s==1&&e==n) //情况3
{
printf("yes\n%d %d\n",s,e);
}
else if(s!=1&&e!=n) //情况4
{
if((a[s]<a[e+1])&&(a[e]>a[s-1]))
{
printf("yes\n%d %d\n",s,e);
}
else
{
printf("no\n");
}
} }
}
return 0;
}

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

  1. Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)

    题目链接:http://codeforces.com/contest/451/problem/B --------------------------------------------------- ...

  2. 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 ...

  3. Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array

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

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

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

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

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

  6. Codeforces Round #258 (Div. 2) . Sort the Array 贪心

    B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...

  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. perl 访问网站一些useragent的设置

    121.40.205.143 - - [22/Jun/2016:12:56:23 +0800] "GET /wechat/account.html HTTP/1.1" 200 34 ...

  2. android doGet和doPost

    doGet和doPost的差别 get和post是http协议的两种方法,另外还有head, delete等  这两种方法有本质的差别,get仅仅有一个流,參数附加在url后.大小个数有严格限制且仅仅 ...

  3. DJ_Java_Decompiler新手入门教程

    首先声明:这篇文章并不是我原创,只是感觉挺有用处,想跟大家分享一下,所以标注为原创,希望能有更多的朋友可以看到,还请原作者谅解. 昨天大D说让我写下DJ入门的基础,今天写了一大半了,结果不小心把浏览器 ...

  4. C++不支持Unicode,即使utf8

    今天,字符串unicode我们已经不需要常理的理由,但是,一些有编程语言的悠久历史.这仍然是一个头疼. 尽管第三方库支持的假设,C++事实上没有真正有效地支持unicode.即使utf8.(注意:本文 ...

  5. Codeforces Round #246 (Div. 2) —B. Football Kit

    B. Football Kit time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...

  6. Domain Model(领域模型)

    Domain Model(领域模型) 上一篇:<DDD 领域驱动设计-如何 DDD?> 开源地址:https://github.com/yuezhongxin/CNBlogs.Apply. ...

  7. MSF 离线攻击

    MSF 离线攻击 MSF连环攻击在internet上实现是不太现实的,网络中的安全设备(防火墙.入侵检测.入侵防护系统). 实验拓扑如下: 实验说明:安全实验中的包过滤防火墙在测试中使用的是linux ...

  8. HDU 4028 The time of a day STL 模拟题

    暴力出奇迹.. #include<stdio.h> #include<iostream> #include<algorithm> #include<vecto ...

  9. HTML5游戏开发进阶指南

    <HTML5游戏开发进阶指南> 基本信息 作者: (印)香卡(Shankar,A.R.)    译者: 谢光磊 出版社:电子工业出版社 ISBN:9787121212260 上架时间:20 ...

  10. Java參数传递方式

    原文:http://blog.sina.com.cn/s/blog_59ca2c2a0100qhjx.html,我作了些改动并添加了一个实例,添加对照 本文通过内存模型的方式来讨论一下Java中的參数 ...