B - Sort the Array
来源:互联网 发布:域名为什么要买 编辑:程序博客网 时间:2024/05/21 09:04
找出一个递减序列,如果有两个或两个以上递减序列直接no了,然后对递减序列两端数start,end,然后比较a[start]和a[end+1] , a[end] 和a[start-1]
#include<iostream>
#include<stdio.h>
using namespace std;
int a[100005];
int main(){
// freopen("in.txt","r",stdin);
int n;
while(~scanf("%d",&n)){
a[0]=-1;
a[n+1]=1000000009;
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
int start=-1,end=-1,flag=0;
for(int i=2;i<=n+1;i++){
if(a[i-1]>a[i] && start==-1){
start=i-1;
}
else if(start!=-1 && end==-1 && a[i-1]<a[i]){
end=i-1;
flag=1;
}
else if(a[i-1]>a[i] && start!=-1 && end!=-1){
flag=2;
break;
}
}
// cout<<"初始位置:"<<start<<" "<<end<<endl;
if(n==1 || start==end){
cout<<"yes"<<endl;
cout<<"1 1"<<endl;
}
else if(flag==2){
cout<<"no"<<endl;
}
else if(a[start]<a[end+1] && a[end]>a[start-1]){
cout<<"yes"<<endl;
cout<<start<<" "<<end<<endl;
}
else
cout<<"no"<<endl;
}
}
- B - Sort the Array
- B. Sort the Array
- codeforce-B. Sort the Array
- 451 B. Sort the Array
- 451B - Sort the Array
- Codeforces 451B Sort the Array
- Codeforces 451B Sort the Array(水题)
- codeforce 451B Sort the Array
- Codeforces 451 B. Sort the Array
- CF 258B. Sort the Array
- CodeForces 451B Sort the Array
- CodeForces 451B. Sort the Array
- codeforces 451B Sort the Array
- Codeforces #258 (Div. 2) B. Sort the Array
- Codeforces Round #258 (Div. 2) 2B Sort the Array
- Codeforces Round #258 (Div. 2) B. Sort the Array
- Codeforces Div. 2 #258-B. Sort the Array
- CodeForces 451B Sort the Array(排序,逆序)
- Oracle数据字典和动态视图小结
- mysql has gone away
- ARC between Foundation and Core Foundation
- 【Z-Stack发送函数AF_DataRequest】
- Android 开发利用wifi调试简介
- B - Sort the Array
- Weblogic10.3.5 数据库连接问题
- cassandra 批量插入
- Hibernate 连接查询
- 实现触摸的类的继承方法有2种
- 从本地上传整个文件夹到hdfs的java程序
- yum使用
- 【java项目实战】dom4j解析xml文件,连接Oracle数据库
- tomcat下配置https环境