题目链接: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. 16位图像Alpha混合的实现(用汇编写的,比MMX还要快)

    Alpha 混合的算法很简单,基于下面的公式就可以实现: D := A * (S - D) / 255 + D D 是目标图像的像素, S 是源图像的像素 A 是 Alpha 值, 0 为全透明, 2 ...

  2. PYQT4 + Python2.6 + eric4-4.2.2a的安装全过程

    PYQT4 + Python2.6 + eric4-4.2.2a的安装全过程 - beike - ITeye技术网站 PYQT4 + Python2.6 + eric4-4.2.2a的安装全过程 博客 ...

  3. discuz清空session,导致session保存机制失败,session无法更新与解决

    <?php function userErrorHandler() { $e = func_get_args(); echo '<pre style="color:red;&qu ...

  4. Android中关于JNI 的学习(六)JNI中注冊方法的实现

    在前面的样例中,我们会发现,当在Java类中定义一个方法的时候,例如以下: public class ParamTransferTest { public static int testval = 1 ...

  5. Android架构设计和软硬整合完整训练

    Android架构设计和软硬整合完整训练 Android架构设计和软硬整合完整训练:HAL&Framework&Native Service&Android Service&a ...

  6. “>>”和“>>>” java

    “>>”算术右移运算符, 表示带符号右移,它使用最高位填充移位后左侧的空位.右移的结果为:每移一位,第一个操作数被2除一次,移动的次数由第二个操作数确定.按二进制形式把所有的数字向右移动对 ...

  7. 管理处理器的亲和性(affinity)

    管理处理器的亲和性(affinity) 管理处理器的亲和性(affinity)

  8. 【C#遗补】之Char.IsDigit和Char.IsNumber的区别

    原文:[C#遗补]之Char.IsDigit和Char.IsNumber的区别 Char中IsDigit和IsNumber的两个方法都是用来判断字符是否是数字的,那他们有什么区别 IsDigit    ...

  9. 【Ruby】Ruby的model学习——Active Record Associations

    在阅读的过程中有不论什么问题,欢迎一起交流 邮箱:1494713801@qq.com    QQ:1494713801 一.怎样定义关联 两个model之间经常会存在关联关系,为了解决这些关联引起的复 ...

  10. poj2528(线段树)

    题目连接:http://poj.org/problem?id=2528 题意:在墙上贴海报,海报可以互相覆盖,问最后可以看见几张海报 分析:离散化+线段树,这题因为每个数字其实表示的是一个单位长度,因 ...