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的更多相关文章

  1. HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array

    Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...

  2. HDU - 5532 Almost Sorted Array (最长非严格单调子序列)

    We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, sele ...

  3. hdu 5532 Almost Sorted Array(模拟)

    Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...

  4. HDU 5532 Almost Sorted Array (最长非递减子序列)

    题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...

  5. HDU 5532——Almost Sorted Array——————【技巧】

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  6. hdu 5532 Almost Sorted Array (水题)

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  7. hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  8. hdoj--5532--Almost Sorted Array(正反LIS)

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

  9. Almost Sorted Array(o(nlgn)求解LIS)

    Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Ot ...

随机推荐

  1. Python自动化运维开发实战 三、python文件类型

    导语: python常用的有3种文件类型 1. 源代码 py 2. 字节代码 pyc 3. 优化代码 pyo 源代码: python源代码的文件以”py"为扩展名,由python程序解释,不 ...

  2. linux下arm汇编的常用指令解析

    1. ldr 和 str : (1) ldr 作为指令,叫做寄存器加载指令.将内存中的值加载到寄存器中. (2) ldr 作为伪指令,实现一个32位常数或地址值加载到寄存器中.后面加载的常量或地址值标 ...

  3. centos6 7 yum安装mongodb 3.6

    配置MongoDB的yum源 # 编辑文件 vim /etc/yum.repos.d/mongodb-org-3.6.repo # 添加以下内容 [mongodb-org-3.6] name=Mong ...

  4. Eclipse git 冲突合并

    Eclipse有一个git的插件叫EGit,用于实现本地代码和远程代码对比.合并以及提交.但是在本地代码和远程代码有冲突的时候,EGit的处理方案还是有点复杂.今天就彻底把这些步骤给理清楚,并公开让一 ...

  5. 抖音爆火的随机点名Java实现原理,没有连接数据库

    抖音爆火的随机点名Java实现原理,没有连接数据库 import java.util.Random; public class Array{ public static void main(Strin ...

  6. tomcat实现https

    第一步:生成key文件: C:\>keytool -genkey -alias tomcat -keyalg RSA -keystore C:\tomcat.key 密码最好设置默认change ...

  7. Python设计模式 - 总览(更新中...)

    最近打算重构部分python项目,有道是"工欲善其事,必先利其器",所以有必要梳理一下相关设计模式.每次回顾基本概念或底层实现时都会有一些新的收获,希望这次也不例外. 本系列打算先 ...

  8. python基础入门学习2

    python 整体注释:选中所有然后CTRL+? 运算符 + - * /   **  %  // 布尔值 true 真  False 假 !=不等于 <>不等于 算数运算,赋值运算,比较运 ...

  9. 让Ubuntu可以压缩/解压缩RAR文件

    ubuntu刚安装的时候是不能解压rar文件的,只有在安装了解压工具之后,才可以解压. 安装:sudo apt-get install unrar卸载:sudo apt-get remove unra ...

  10. WAS 与IHS集成问题

    1.安装好WAS与IHS后 发布Web发现无法启动 查阅资料后发现缺少插件Plugins 于是去下载安装对应版本的Plugins 发现还是有问题 后来想起发布web01时,插件还未安装.因此重新发布一 ...