Codeforces Round #258 (Div. 2) B. Sort the Array
题目链接: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的更多相关文章
- Codeforces Round #258 (Div. 2) B. Sort the Array(简单题)
题目链接:http://codeforces.com/contest/451/problem/B --------------------------------------------------- ...
- 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 ...
- Codeforces Round #258 (Div. 2/B)/Codeforces451B_Sort the Array
解题报告 http://blog.csdn.net/juncoder/article/details/38102391 对于给定的数组,取对数组中的一段进行翻转,问翻转后是否是递增有序的. 思路: 仅 ...
- Codeforces Round #258 (Div. 2)[ABCD]
Codeforces Round #258 (Div. 2)[ABCD] ACM 题目地址:Codeforces Round #258 (Div. 2) A - Game With Sticks 题意 ...
- Codeforces Round #258 (Div. 2) 小结
A. Game With Sticks (451A) 水题一道,事实上无论你选取哪一个交叉点,结果都是行数列数都减一,那如今就是谁先减到行.列有一个为0,那么谁就赢了.因为Akshat先选,因此假设行 ...
- Codeforces Round #258 (Div. 2) . Sort the Array 贪心
B. Sort the Array 题目连接: http://codeforces.com/contest/451/problem/B Description Being a programmer, ...
- Codeforces Round #258 (Div. 2)
A - Game With Sticks 题目的意思: n个水平条,m个竖直条,组成网格,每次删除交点所在的行和列,两个人轮流删除,直到最后没有交点为止,最后不能再删除的人将输掉 解题思路: 每次删除 ...
- 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 ...
- Codeforces Round #258 (Div. 2)-(A,B,C,D,E)
http://blog.csdn.net/rowanhaoa/article/details/38116713 A:Game With Sticks 水题.. . 每次操作,都会拿走一个横行,一个竖行 ...
随机推荐
- [Android学习笔记]Bitmap,BitmapDrawable,BitmapFactory学习笔记
Bitmap:图片文件的封装,可以看做是一张位图此类中的静态方法可以通过源Bitmap创建新的Bitmap对象此类封装了位图的一些信息Bitmap文档 BitmapFactory:一个工具类,用于创建 ...
- [Cocos2d-x]博客推荐
推荐一下大神们的博客: JackyStudio: http://blog.csdn.net/jackyvincefu/article/category/1591201/3 老G的小屋: http:// ...
- HBase总结(二十)HBase经常使用shell命令具体说明
进入hbase shell console $HBASE_HOME/bin/hbase shell 假设有kerberos认证,须要事先使用对应的keytab进行一下认证(使用kinit命令),认证成 ...
- Oracle“记录被另一个用户锁住” 无法更新删除的解决办法
1.查看数据库锁,诊断锁的来源及类型: select object_id,session_id,locked_mode from v$locked_object; 或者用以下命令: select b. ...
- MyCAT部署及实现读写分离(转)
MyCAT是mysql中间件,前身是阿里大名鼎鼎的Cobar,Cobar在开源了一段时间后,不了了之.于是MyCAT扛起了这面大旗,在大数据时代,其重要性愈发彰显.这篇文章主要是MyCAT的入门部署. ...
- [Backbone]Make Backbone Better With Extensions
Backbone is becoming wildly popular as a web application development framework. Along with this popu ...
- hdu4280(最大流)
传送门:Island Transport 题意:有N个岛屿 M条无向路 每个路有一最大允许的客流量,求从最西的那个岛屿最多能运用多少乘客到最东的那个岛屿. 分析:无向图正反都加弧,权值一样,这题点多, ...
- Linux中进行挂起(待机)的命令说明
/********************************************************************* * Author : Samson * Date ...
- hdu1698(线段树)
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1698 线段树功能:update:成段替换 (由于只query一次总区间,所以可以直接输出1结点的信息) ...
- 【转】真正的Acmer
上海交大 戴文渊 大牛写的东西,建议大家看看 yiyiyi4321 2007-07-10 13:49:30.0 http://dwyak.spaces.live.com/?_c11_BlogPart_ ...