B - Sort the Array
找出一个递减序列,假设有两个或两个以上递减序列直接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的更多相关文章
- CF451B Sort the Array 水题
Codeforces Round #258 (Div. 2) Sort the Array B. Sort the Array time limit per test 1 second memory ...
- [CareerCup] 11.2 Sort Anagrams Array 异位词数组排序
11.2 Write a method to sort an array of strings so that all the anagrams are next to each other. 这道题 ...
- 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) 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 ...
- [LeetCode] 912. Sort an Array 数组排序
Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1] Outp ...
- LeetCode 912. 排序数组(Sort an Array) 43
912. 排序数组 912. Sort an Array 题目描述 每日一算法2019/6/15Day 43LeetCode912. Sort an Array
- Minimum number of swaps required to sort an array
https://www.hackerrank.com/challenges/minimum-swaps-2/problem Minimum Swaps II You are given an unor ...
- 【leetcode】912. Sort an Array
题目如下: Given an array of integers nums, sort the array in ascending order. Example 1: Input: [5,2,3,1 ...
- 【LeetCode】912. Sort an Array 解题报告(C++)
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 库函数排序 桶排序 红黑树排序 归并排序 快速排序 ...
随机推荐
- LuoguP5017 摆渡车 $dp$
题意 戳这里 吐槽 听同学说今年\(pjT3\)很难,于是就去看了下. 一眼斜率优化...为什么\(n,m\)这么小啊... 感觉这题出的还是不错的. Solution 首先我们先转化一波题意:给出数 ...
- Java基础学习——多线程之线程池
1.线程池介绍 线程池是一种线程使用模式.线程由于具有空闲(eg:等待返回值)和繁忙这种不同状态,当数量过多时其创建.销毁.调度等都会带来开销.线程池维护了多个线程,当分配可并发执行的任务时, ...
- 2、Redis的基础知识
写在前面的话:读书破万卷,编码如有神 -------------------------------------------------------------------- 主要内容包括: red ...
- MySQL的五种日期和时间类型
MySQl中有多种表示日期和时间的数据类型.其中YEAR表示年份,DATE表示日期,TIME表示时间,DATETIME和TIMESTAMP表示日期和实践.它们的对比如下:YEAR ,字节数 ...
- generator自动生成mybatis的xml配置
generator自动生成mybatis的xml配置.model.map等信息:1.下载mybatis-generator-core-1.3.2.jar包. 网址:http://code. ...
- 不用windows不会死
不用windows不会死 近期看到win8广告,仅仅要2999元. 事实上他们不知道,不用windows不但不会死,还会活得更好. 不信.你去问问那些非windows用户,他们是不是非常快乐?烦恼非常 ...
- VS中运行HTTP 无法注册URL
参考资料 http://www.java123.net/detail/view-449670.html http://www.cnblogs.com/jiewei915/archive/2010/06 ...
- 深入浅出VC++串口编程之基于Win32 API
1.API描述 在WIN32 API中,串口使用文件方式进行访问,其操作的API基本上与文件操作的API一致. 打开串口 Win32 中用于打开串口的API 函数为CreateFile,其原型为: H ...
- android NDK 开发环境搭建
基于 Android NDK 的学习之旅-----环境搭建 工欲善其事必先利其器 , 下面介绍下 Eclipse SDK NDK Cygwin CDT 集成开发环境的搭建. 1.Android 开发环 ...
- .NET:CLR via C# Manifest
An assembly is a collection of one or more files containing type definitions and resource files. One ...