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. HttpWatch手把手图解教程

    HttpWatch手把手图解教程,提供HttpWatch下载,教您安装使用,一步到位 一 HttpWatch下载: HttpWatchProv7.2.13 破解版(带正版key) 授权:共享软件 大小 ...

  2. isPlainObject的解释

    参考: http://www.365mini.com/page/jquery_isplainobject.htm 先来看下使用案例: //在当前页面内追加换行标签和指定的HTML内容 function ...

  3. 吴裕雄 python神经网络(6)

    import randomimport numpy as npnp.random.randint(0,49,3) ##required libarariesimport tensorflow as t ...

  4. jenkins 自动触发

    在gitlab上配置连接jenkins ,将Jenkins的Secret token 与Build URL 复制到gitlab中 在settings标签下面,找到OutBound Request,勾选 ...

  5. 线段树模板(HDU 6356 Glad You Came)

    题目: HDU 6356 http://acm.hdu.edu.cn/showproblem.php?pid=6356 很裸的线段树 #include<bits/stdc++.h> #de ...

  6. Shader基础(固定管线着色器)

    在Shader的编码中,要养成不加空格的习惯,否则会有时候出现一些错误 固定管线着色器: 优点:实现简单 缺点:处理的效果比较差 //设置Shader的路径 Shader "MyFixedS ...

  7. python return 及lambda函数

    return有两个作用: 1.用来返回函数的运行结果,或者调用另外一个函数.比如max()函数 >>> def fun(a,b): #返回函数结果. return max(a,b) ...

  8. 581. Shortest Unsorted Continuous Subarray

      Given an integer array, you need to find one continuous subarray that if you only sort this subarr ...

  9. jpa orderby

    return criteriaQuery.where(in).orderBy(new OrderImpl(root.get("field1"))).getRestriction() ...

  10. oracle 中更新update不成功的原因

    oracle 中执行insert into 与delete 都正常,但是执行update 却没有反应. 原因: 是因为记录锁.这种只有update无法执行其他语句可以执行的其实是因为记录锁导致的,在o ...