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 ...
随机推荐
- easyui中的几个问题
easyui中的tree,采用url参数读取json,无法显示.有可能是vs的IIS不支持,$.ajax 原因待测试,有知道的朋友也可以贴代码,我解决的一个办法是 $(function () { $. ...
- 做好Unity4.x开发项目规划
1. 是否要用lua 2. (对于需操作的游戏)客户端游戏如何做战斗验证 下面列举小坑吧.不建议都绕开,毕竟没有那么多时间做前期调研的. 对应版本Unity4.x 1. 客户端程序层面 总的来说C#超 ...
- 学习JS的心路历程-参数的传递(下)
今天我们要来探讨JS到底是透过何种参数传递方式呢? 废话不多说,上示例!! 我们先声明原始型别和物件型别来看看两者是否会有不一样的差异: var myStr = 'Hola': var myObj = ...
- opencv 对RGB图像直接二值化
#include <opencv2/opencv.hpp> #include <iostream> using namespace cv; using namespace st ...
- pandas 中的常用数学计算
1.开方: >>> s = pd.Series([1.2 + 1j]) >>> s.abs()
- Real Time Rendering 1
[Real Time Rendering 1] 1.RTR是一本导论.官网:http://www.realtimerendering.com. 2.At around 6 fps, a sense o ...
- 在centos xmanager工具环境下启动 xwindow
# 安装epel源 [root@linuxidc ~]# yum install -y epel-release # 安装lightdm和Xfce 1.安装 lightdm sudo yum inst ...
- Tableau-安装的坑
前言: 为了学习Tableau的教程,我下载了这个软件从官网,结果安装的时候一直报一个奇怪的错误, 由于当时没有截图,只记得错误代码Xo80076666好像是,提示安装失败,已经有另一个产品安装 在我 ...
- c#实现动态加载Dll(转)
c#实现动态加载Dll 分类: .net2009-12-28 13:54 3652人阅读 评论(1) 收藏 举报 dllc#assemblynullexceptionclass 原理如下: 1.利用反 ...
- c/c++ 中的重要函数
1,strtod: 函数原型: #include <cstdlib> double strtod(const char *nptr, char **endptr); strtod 原型 名 ...