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/ 目录 题目描述 题目大意 解题方法 库函数排序 桶排序 红黑树排序 归并排序 快速排序 ...
随机推荐
- 转 TCP/IP的三次握手与四次挥手详解
TCP((Transmission Control Protocol)传输控制协议,是一个面向连接的协议.在运用此协议进行数据传输前都会进行连接的建立工作(三次握手):当数据传输完毕,连接的双方都会通 ...
- Git 简易使用指南及补充
Git最简易的使用指南 助你开始使用 git 的简易指南,木有高深内容,;) 安装 下载 git OSX 版 下载 git Windows 版 下载 git Linux 版 创建新仓库 创建新文件夹, ...
- 【POJ】1419:Graph Coloring【普通图最大点独立集】【最大团】
Graph Coloring Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 5775 Accepted: 2678 ...
- python日常碎碎念--PIL
昨天在处理网站相关图片的时候,发现图片都大小不一样,虽然一下就能想起PIL这个库,但是用法却不记得了. 简单记录一下用法. 可以直接用 Image.open 来打开图片,PIL库为这个文件对象提供了各 ...
- codevs 1001 舒适的线路 kruskal/gcd
舒适的线路 Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://www.codevs.cn/problem/1001/ Description Z小 ...
- UVALive 4867 Maximum Square 贪心
E - Maximum Square Time Limit:4500MS Memory Limit:0KB 64bit IO Format:%lld & %llu Submit ...
- LR监控Apache资源
前提本文使用的是lampp环境下自带的Apache服务 步骤1.修改Apache中Httpd.conf文件,添加如下代码:文件位置为:/opt/lampp/etc/httpd.conf,如下图: &l ...
- spring---aop(8)---Spring AOP中optimize
写在前面 optimize是ProxyConfig的属性.意思为 是否对生产代理策略使用优化. public class ProxyConfig implements Serializable { p ...
- CentOS的update-grub2命令
这个和Ubuntu还是有些区别,在CentOS修改成如下: grub2-mkconfig -o /boot/grub2/grub.cfg
- Send a WhatsApp Message programatically -- Tasker WhatsTasker
Here is My code snippet: Uri mUri = Uri.parse("smsto:+9876543210"); Intent mIntent = new I ...