题目大意:给一个n个数的序列,问这个序列删掉一个数后是否有序。

题目分析:找最长上升子序列和最长下降子序列,只要有一个的长度不小于n-1即可。

代码如下:

# include<iostream>
# include<cstdio>
# include<cmath>
# include<vector>
# include<list>
# include<queue>
# include<map>
# include<set>
# include<cstring>
# include<algorithm>
using namespace std; const int N=100005; int n;
int a[N+5];
int dp[N+5];
int d[N+5]; int f(int l,int r,int x)
{
while(l<r)
{
int mid=l+(r-l)/2;
if(d[mid]<=x)
l=mid+1;
else
r=mid;
}
return l;
} int f1(int l,int r,int x)
{
while(l<r)
{
int mid=l+(r-l)/2;
if(d[mid]>=x)
l=mid+1;
else
r=mid;
}
return l;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
for(int i=0;i<n;++i) scanf("%d",a+i);
d[0]=a[0];
int cnt=0;
int len=1;
for(int i=1;i<n;++i){
if(a[i]>=d[len-1])
d[len++]=a[i];
else{
int pos=f(0,len,a[i]);
d[pos]=a[i];
}
}
if(len>=n-1)
++cnt;
d[0]=a[0];
len=1;
for(int i=1;i<n;++i){
if(a[i]<=d[len-1]){
d[len++]=a[i];
}else{
int pos=f1(0,len,a[i]);
d[pos]=a[i];
}
}
if(len>=n-1)
++cnt;
if(cnt==0)
printf("NO\n");
else
printf("YES\n");
}
return 0;
}

  

HDU-5532 Almost Sorted Array (LIS)的更多相关文章

  1. hdu 5532 Almost Sorted Array(模拟)

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

  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 s ...

  4. leetcode 之Search in Rotated Sorted Array(四)

    描述 Follow up for ”Search in Rotated Sorted Array”: What if duplicates are allowed?    Would this aff ...

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

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

  6. Remove Duplicates from Sorted Array(参考)

    Given a sorted array, remove the duplicates in place such that each element appear only once and ret ...

  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. LeetCode 之 Merge Sorted Array(排序)

    [问题描写叙述] Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array ...

  9. HDU 1257 最少拦截系统 ——(LIS)

    想了一下感觉和lis有关,交了果然AC.想不到很好的证明方法,试做证明如下:lis的每一个点都是一个不上升系统中的一员,设其为a[i],那么a[i-1]<a[i]肯定是成立的(lis的性质),夹 ...

随机推荐

  1. ios开发逆向传值的几种方法整理

    第一种:代理传值 第二个控制器: @protocol WJSecondViewControllerDelegate <NSObject> - (void)changeText:(NSStr ...

  2. acvitity的日常 启动模式(上)

    1. 基本介绍 大家平时只要懂一点Android知识的话,都一定会知道,一个应用的组成,往往包含了许多的activity组件,每个activity都应该围绕用户的特定动作进行跳转设计.比如说,一个电话 ...

  3. 类似github的框架

    github是程序员经常上的网站,但如果是在一家苦逼不能访问外网的公司,那不能把自己的代码托管在github上绝对是一件非常痛苦的事情.如果想要在公司内网也可以用github托管自己的代码,那就要自己 ...

  4. Jquery实现的Tabs标签页

    效果图: HTML: <div class="tabs"> <ul id="tabs"> <li class="tab- ...

  5. Apache目录结构(一)

    一.Apache 目录结构 bin: 该目录用于存放apache常用的命令,比如httpd cig-bin:该目录存放linux下的常用命令 .sh conf:存放配置文件httpd.conf,在ht ...

  6. (转)tomcat与地址栏图标之研究(多浏览器)

    原文:http://hi.baidu.com/hebo_thu/item/fc8c81bb164f5cee4fc7fd90 tomcat与地址栏图标之研究(多浏览器) 最近在做一个java网络应用程序 ...

  7. 技术分享:逆向分析ATM分离器

    文章内容仅供技术交流,请勿模仿操作! 背景(作者) 每一次外出时, Elizabeth和我总是格外的小心,同时把我们身上的钱藏在特殊的皮带上面,这样还不够,我们还采取了“狡兔三窟”的方式来藏身上带的银 ...

  8. 如何用JS判断网页中某个id的网页元素是否存在

    <meta http-equiv="content-type" content="text/html;charset=utf-8" /> <m ...

  9. C++ Primer----一个关于 vector 的有趣的问题

    大家请看下面的代码,请问 输出结果是?? /** * @file vector-destroy.cc * @brief an interesting problem regarding vector ...

  10. js中的apply调用

    今天看了阮一锋老师的一篇文章,感觉很明了对闭包的理解,尤其是文章中的apply的介绍 apply()是函数对象的一个方法,它的作用是改变函数的调用对象,它的第一个参数就表示改变后的调用这个函数的对象. ...