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/ 目录 题目描述 题目大意 解题方法 库函数排序 桶排序 红黑树排序 归并排序 快速排序 ...
随机推荐
- 2018-2019-2 20162318《网络对抗技术》Exp3 免杀原理与实践
一.实验内容 1.正确使用msf编码器,msfvenom生成如jar之类的其他文件,veil-evasion),加壳工具),使用shellcode编程 2.通过组合应用各种技术实现恶意代码免杀(如果成 ...
- 安卓中WebKit的使用
1.在安卓开发中,使用webkit显示网页 步骤: ①初始化一个webkit控件: ②获取webkit的WebSettings对象: ③设置javascript为enable ④为webkit设置&q ...
- jmeter-分布式部署之负载机的设置
本文分三个部分: 1.windows下负载机的配置 2.Linux下负载机的配置 3.遇到的问题 *************************************************** ...
- linux下面mmap和setsignal函数用法
#include <stdio.h> #include <stdlib.h> #include <sys/mman.h> #include <fcntl.h& ...
- Tomcat – java.lang.OutOfMemoryError: PermGen space Cause and Solution
Read more: http://javarevisited.blogspot.com/2012/01/tomcat-javalangoutofmemoryerror-permgen.html#ix ...
- JS浮点数运算
//乘法函数,用来得到精确的乘法结果 //说明:javascript的乘法结果会有误差,在两个浮点数相乘的时候会比较明显.这个函数返回较为精确的乘法结果. //调用:accMul(arg1,arg2) ...
- java线程的一些基础小知识
--------------------------------------------------------------------------------------------------线程 ...
- ubuntu C++开发环境
最近在VM中装了Ubuntu,为了开发程序,于是在网上找了些由于C/C++开发环境搭建的资料,供大家参考. 以下文字主要讲如何搭建Code::Blocks+wxWidgets. 搭建步骤: 1.安装编 ...
- Weblogic下启用Gzip压缩
一.首先,去http://sourceforge.net/projects/filterlib网站下载tk-filters-1.0.1.zip. 二.解压这个tk-filters-1.0.1.zip压 ...
- 转 dockerfile 介绍 及 编写
Docker简介 Docker项目提供了构建在Linux内核功能之上,协同在一起的的高级工具.其目标是帮助开发和运维人员更容易地跨系统跨主机交付应用程序和他们的依赖.Docker通过Docker容器, ...