题目链接: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. 实时人脸检测 (Real-Time Face Detection)

    源地址:http://blog.sina.com.cn/s/blog_79b67dfe0102uzra.html 最近需要用到人脸检测,于是找了篇引用广泛的论文实现了一下:Robust Real-Ti ...

  2. oschina图形和图像工具开源软件

    图形和图像工具开源软件 http://www.oschina.net/project/tag/181/imagetools?sort=view&lang=21&os=0

  3. iOS_10_tableView的简单使用_红楼十二钗

    终于效果图: 方式1,用字典数组 BeyondViewController.h // // BeyondViewController.h // 10_tableView // // Created b ...

  4. OCP读书笔记(10) - 使用闪回技术I

    使用闪回技术查询数据 闪回查询:就是查询表在过去某个时间点的数据,所用到的技术就是undo数据 SQL> conn scott/tiger 创建测试表 SQL> create table ...

  5. ubuntu/linux mint 创建proc文件的三种方法(四)

    在做内核驱动开发的时候,能够使用/proc下的文件,获取对应的信息,以便调试. 大多数/proc下的文件是仅仅读的,但为了演示样例的完整性,都提供了写方法. 方法一:使用create_proc_ent ...

  6. IE 加速插件之 Google Chrome Frame

    前言 IE 8 及以下版本的速度较慢. 特别是前端的js 和 css 内容较多时尤为突出. 就笔者的开发经验来说GWT, Ext JS, raphael , draw2d 等开发的系统在IE下使用是相 ...

  7. CodeForce 356A Knight Tournament(set应用)

     Knight Tournament time limit per test 3 seconds memory limit per test 256 megabytes input standard ...

  8. c++里的类型转化

    c++里的类型转换种类 在c++里包含4种,static_cast,dynamic_cast,const_cast,reinterpret_cast. 4种类型 reinterpret_cast: 强 ...

  9. 在Windows下搭建React Native Android开发环境

    widows版本: win7 64位 专业版 1. 安装jdk.(我用的jdk7) 注意选择x86还是x64版本, 添加到系统PATH环境变量 2. 准备好android sdk 这个不多说,同时推荐 ...

  10. 在阿里云的CentOS环境中安装django

    购买了一台阿里云主机.操作系统为CentOS 6.5.准备在上面跑Django做Web开发.因为CentOS自带的python版本号较低,安装Django先要安装新版本号python.还是费了点周折. ...