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 水题.. . 每次操作,都会拿走一个横行,一个竖行 ...
随机推荐
- 简单的 "双缓冲" 绘图的例子(研究一下)
所谓双缓冲就是先画到内存画布(如: TBitmap), 然后再转帖到目的地. 譬如下面小程序: procedure TForm1.FormCreate(Sender: TObject); begin ...
- 使用ffmpeg 对视频截图,和视频转换格式
//执行CMD命令方法 public static void CmdProcess(string command)//调用CMD { //实例化一个进程类 ...
- Free Mind » Blog Archive » Yakuake + dtach vs Screen + urxvt
Free Mind » Blog Archive » Yakuake + dtach vs Screen + urxvt Yakuake + dtach vs Screen + urxvt
- VMware vSphere服务器虚拟化实验十五 vCenter vShield Manager
VMware vSphere服务器虚拟化实验十五 vCenter vShield Manager VMware vShield Manager是专为 VMware vCenter Server 集成 ...
- poj 3278 Catch That Cow (bfs搜索)
Catch That Cow Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 46715 Accepted: 14673 ...
- VSTO之旅系列(五):创建Outlook解决方案
原文:VSTO之旅系列(五):创建Outlook解决方案 本专题概要 引言 Outlook对象模型 自定义Outlook窗体 小结 一.引言 在上一个专题中,为大家简单介绍了下如何创建Word解决方案 ...
- jvm理论
三大流行jvm sun HotSpot ibm j9 BEA JRockit Oracle 会基于HotSpot整合 JRockit. jvm运行时数据区 java虚拟机所管理的内存将会包括以下几个运 ...
- SqlServer操作远程数据库
exec sp_addlinkedserver 'srv2','','mssql2008','服务器IP' exec sp_addlinkedsrvlogin 'srv2','false',null, ...
- dell N5010
Inspiron N5010Microsoft Windows 10 企业版 (64位) (英特尔)Intel(R) Core(TM) i3 CPU M 370 @ 2.40GHz(24 ...
- python基础课程_2学习笔记3:图形用户界面
图形用户界面 丰富的平台 写作Python GUI程序前,须要决定使用哪个GUI平台. 简单来说,平台是图形组件的一个特定集合.能够通过叫做GUI工具包的给定Python模块进行訪问. 工具包 描写叙 ...