hdu 5532 (LIS) Almost Sorted Array
http://acm.hdu.edu.cn/showproblem.php?pid=5532
题意大致是一组数中去掉一个数后问剩下的数是否构成非严格单调序列
正反各跑一遍最长非严格连续子序列,存在长度大于等于n-1的就满足YES,注意这里的YES NO都是大写
#include<cstdio>
using namespace std;
int a[],c[];
int main()
{
int t,i,j,n;
scanf("%d",&t);
while (t--)
{
scanf("%d",&n);
for (i=;i<=n;i++)
scanf("%d",&a[i]);
int ans=;
c[ans]=a[];
for (i=;i<=n;i++)
{
if (a[i]>=c[ans]) c[++ans]=a[i];
else if (a[i]<c[]) c[]=a[i];
else{
int left=,right=ans,mid;
while (left<right-)
{
mid=(left+right)/;
if (a[i]>=c[mid]) left=mid;
else right=mid;
}
if (a[i]<=c[right]) c[right]=a[i];
}
}
if (ans>=n-){
printf("YES\n");continue;
}
ans=;
c[ans]=a[n];
for (i=n-;i>=;i--)
{
if (a[i]>=c[ans]) c[++ans]=a[i];
else if (a[i]<c[]) c[]=a[i];
else{
int left=,right=ans,mid;
while (left<right-)
{
mid=(left+right)/;
if (a[i]>=c[mid]) left=mid;
else right=mid;
}
if (a[i]<=c[right]) c[right]=a[i];
}
}
if (ans>=n-) printf("YES\n");
else printf("NO\n");
}
return ;
}
hdu 5532 (LIS) Almost Sorted Array的更多相关文章
- HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array
Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...
- HDU - 5532 Almost Sorted Array (最长非严格单调子序列)
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, sele ...
- hdu 5532 Almost Sorted Array(模拟)
Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...
- HDU 5532 Almost Sorted Array (最长非递减子序列)
题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...
- HDU 5532——Almost Sorted Array——————【技巧】
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5532 Almost Sorted Array (水题)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdoj--5532--Almost Sorted Array(正反LIS)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- Almost Sorted Array(o(nlgn)求解LIS)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
随机推荐
- JAVA回文
package huiwen; import java.util.Scanner; public class Huiwen { public static void main(String[] arg ...
- lcd 控制器
1. 使用lcd 一般需要一个控制器和驱动器,控制器需要初始化以产生正确的时序,驱动器一般是和lcd基板制作在一起. LCD 控制器结构图: REGBANK 表示调色板 LCDDMA 表示DMA通道 ...
- kotlin 代码习惯1
让你的 Kotlin 代码远离 !! 简评:优雅的运用 Kotlin 的 null safety 特性,而不要简单的直接用 !!. 对于 Null 的检查是 Kotlin 的特点之一.强制你在编码过程 ...
- fs.watchFile
[fs.watchFile] fs.watchFile(filename[, options], listener) Watch for changes on filename. The callba ...
- cdh 安装系列1-- manager 6.01 安装
一.如果是远程centos安装,请参考我得博客,通过xmanager 链接centos桌面 二.Non-production Installation Ideal for trying Clouder ...
- MVC005之页面调用控制器中的方法
描述:控制器在传给页面数据时,有时我们需要对传过来的数据进行二次处理 如: 1:传过来部门编码,但页面上要显示为部门名称 2:格式转换等 我们在写aspx时一般在cs文件中写一个protected的方 ...
- python 常用模块(一): random , time , sys , os模块部分知识.
1.常用模块:(1)collectiaons模块 (2)与时间相关 time模块 (3)random模块 (4)os模块 (5)sys模块 (6) 序列化模块: json , pickle 2 ...
- Numpy:索引与切片
numpy基本的索引和切片 import numpy as np arr = np.array([1,2,3,555,666,888,10]) arr array([ 1, 2, 3, 555, 66 ...
- css设计技巧
如果设置了样式发现没有效果,可以把需要调的元素或者父元素等设置一下背景,然后看看哪个父元素或子元素有样式控制,可以清除一下.
- 数据库类型空间效率探索(四)-tinyint与enum与set
mysql> select count(*) from userinfo;+----------+| count(*) |+----------+| 115597 |+----------+1 ...