Input
The first line contains an integer T indicating the total number of test cases. Each test case starts with an integer n in one line, then one line with n integers a1,a2,…,an.

1≤T≤2000
2≤n≤105
1≤ai≤105
There are at most 20 test cases with n>1000.

 
Output
For each test case, please output "`YES`" if it is almost sorted. Otherwise, output "`NO`" (both without quotes).
 
Sample Input
3
3
2 1 7
3
3 2 1
5
3 1 4 1 5
 
Sample Output
YES
YES
NO

题意:给你一组数,能否删除一个后使他成为升序或者降序

思路:

正反分别求一次最长上升子序列,只要长度有一次≥n-1即可

#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <vector>
#include <algorithm>
#include <functional>
typedef long long ll;
using namespace std;
const int maxn = 1e5 + 5;
int b[maxn];
int n;
int Search(int num,int low,int high)
{
int mid;
while(low <= high)
{
mid = (low+high)/2;
if(num >= b[mid])
low= mid+1;
else
high = mid-1;
}
return low;
} int fin(int *a)
{
int len,pos;
b[1] = a[1];
len = 1;
for(int i = 2;i <= n;i++)
{
if(a[i] >= b[len])
{
len = len+1;
b[len] = a[i];
}
else
{
pos = Search(a[i],1,len);
b[pos ] = a[i];
}
}
if(len >= n-1)
return true;
else
return false;
} int t[maxn],tt[maxn]; int main()
{
int cas;
scanf("%d",&cas);
while(cas--)
{
scanf("%d",&n);
for(int i = 1;i <= n;i++)
scanf("%d",t+i);
for(int i = 1;i <= n;i++)
tt[n+1-i] = t[i];
bool flag = fin(t);
flag |= fin(tt);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}

  

hdu 5532(最长上升子序列)的更多相关文章

  1. hdu 1950 最长上升子序列(lis) nlogn算法【dp】

    这个博客说的已经很好了.http://blog.csdn.net/shuangde800/article/details/7474903 简单记录一下自己学的: 问题就是求一个数列最长上升子序列的长度 ...

  2. HDU 5773 最长上升子序列

    题意 给出一个序列 问它的最长严格上升子序列多长 这个序列中的0可以被替代为任何数 n的范围给出了1e5 所以平常的O(n*n)lis不能用了 在kuangbin的模板里有O(nlogn)的模板 套上 ...

  3. hdu 1950 最长上升子序列

    //Accepted 3540 KB 62 ms //dp 最长上升子序列 #include <cstdio> #include <cstring> #include < ...

  4. HDU 5748 最长上升子序列的长度nlogn(固定尾部)

    Bellovin Time Limit: 6000/3000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total ...

  5. HDU 1025(最长上升子序列)

    题意是要在两条平行线间连点,要在线不交叉的前提下尽可能多的连线,问最多能连多少条线. 现假定题中所给的是 9 组点,分别是:1—3,2—8,3—5,4—9,5—2,6—4,7—6,8—7,9—1,如图 ...

  6. HDU 1159 最长公共子序列(n*m)

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  7. HDU 1159 最长公共子序列

    Common Subsequence Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Other ...

  8. hdu 5773 最长递增子序列 (nlogn)+贪心

    The All-purpose Zero Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Oth ...

  9. HDU - 1503 最长公共子序列记录路径

    题意:先给两个水果的名字然后得出一个最短的序列包含这两个词. 思路:我一开始的思路是先求出最长公共子序列,然后做一些处理将其他的部分输出来:两种水果的字符串和最长公共子序列的字符串这三个字符串做对比, ...

  10. HDU - 1160 最长上升子序列以及记录路径

    题意:第一列,给出老鼠的重量,第二列,给出老鼠的速度,要证明老鼠的重量越大,速度越小,给出最多老鼠的数量,并说明第几只. 思路:先将老鼠按照重量从大到小排序,然后速度是从小到大,求最长上升子序列,学习 ...

随机推荐

  1. hashlib 加密

    import hashlib def md5(args): hash = hashlib.md5(bytes('aaadf',encoding='utf-8')) hash.update(bytes( ...

  2. Windows Server2012 故障转移集群之动态仲裁(Dynamic Quorum)

    本篇文章主要介绍Windows2012的故障转移集群一个新功能“动态仲裁”,默认该功能是开启的: 动态仲裁能在当前群集投票出现分歧的情况下取消某些节点的投票权限,比如偶数个节点的群集环境.仲裁见证和动 ...

  3. 消除ExtJS6的extjs-trila字样

  4. java语法基础(总结)

    1,关键字:其实就是某种语言赋予了特殊含义的单词. 保留字:其实就是还没有赋予特殊含义,但是准备日后要使用过的单词. 2,标示符:其实就是在程序中自定义的名词.比如类名,变量名,函数名.包含 0-9. ...

  5. jmeter入门(02)测试报告各项指标含义

    一.名词定义(时间单位ms) 1.聚合报告 Sample:本次测试场景共运行多少个请求: Average:平均响应时间: Median:统计意义上的响应时间中值: 90% line:所有线程中90%的 ...

  6. SpringCloud的DataRest(三)

    一.进阶配置定义 二.定制显示内容和控制方法使用 1.控制显示的内容 如果想让输出显示的数据始终按我们定义的格式显示: 配置之后返回的JSON数据会按照ListApp定义的数据格式进行输出 2.屏蔽自 ...

  7. hadoop2.7.3+spark2.1.0+scala2.12.1环境搭建(1)安装jdk

    一.文件准备 下载jdk-8u131-linux-x64.tar.gz 二.工具准备 2.1 Xshell 2.2 Xftp 三.操作步骤 3.1 解压文件: $ tar zxvf jdk-8u131 ...

  8. Spring Security 入门(1-9)国际化的使用

  9. MicrosoftWebInfrastructure 之坑

    从svn下载下来的项目,还原提示缺少MicrosoftWebInfrastructure   包 网上大多数解决方法  PM> Install-Package Microsoft.Web.Inf ...

  10. Krajee插件的用法

      第一步: <!-- 必须引入 --> link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/boots ...