hdu 5532
input
1<=T<=2000
2<=n<=10e5
a1 a2 ... an 1<=ai<=10e5
最多二十个n>1000
output
能否从数组中移除一个数使数组变为升序或降序,能输出YES,不能输出NO
做法,用后一个数减前一个数,统计正数的个数和负数的个数,如果全部为正或全部为负肯定可以,一个正或者一个负可能可以,如果这个和前一个或者后一个相加能变成全部正或全部负便可以,因为x1=a[i]-a[i-1],x2=a[i+1]-a[i],则a[i+1]-a[i-1]=x1+x2
#include <cstdio>
#include <queue>
#include <cstring>
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <ctime> using namespace std; int T,n,a,d[];
int main()
{
// freopen("/home/user/桌面/in","r",stdin);
scanf("%d",&T);
while(T--)
{
int les=,gre=,i,t,fa=-,fb=-;
scanf("%d%d",&n,&a);
for(i=;i<n-;i++)
{
scanf("%d",&t);
d[i]=t-a;
if(fa==-&&d[i]<) fa=i;
if(fb==-&&d[i]>) fb=i;
if(d[i]==)
{
les++;
gre++;
}
else d[i]>?gre++:les++;
a=t;
}
//for(int i=0;i<n-1;i++) printf("%d ",d[i]);printf("\n");
if(gre==n-||les==n-)
{
puts("YES");
continue;
}
if(gre==n-)
{
if(fa==||fa==n-||d[fa]+d[fa-]>=)
{
puts("YES");
continue;
}
else if(fa<n-&&d[fa]+d[fa+]>=)
{
puts("YES");
continue;
}
}
if(les==n-)
{
if(fb==||fb==n-||d[fb]+d[fb-]<=)
{
puts("YES");
continue;
}
else if(fb<n-&&d[fb]+d[fb+]<=)
{
puts("YES");
continue;
}
}
puts("NO");
}
//printf("time=%.3lf",(double)clock()/CLOCKS_PER_SEC);
return ;
}
hdu 5532的更多相关文章
- hdu 5532 Almost Sorted Array
http://acm.hdu.edu.cn/showproblem.php?pid=5532 题目大意: 给你一个不规则的序列,问是否能够通过删除一个元素使其成为一个有序的序列(递增或递减(其中相邻 ...
- hdu 5532 (LIS) Almost Sorted Array
http://acm.hdu.edu.cn/showproblem.php?pid=5532 题意大致是一组数中去掉一个数后问剩下的数是否构成非严格单调序列 正反各跑一遍最长非严格连续子序列,存在长度 ...
- 【HDU 5532 Almost Sorted Array】水题,模拟
给出一个序列(长度>=2),问去掉一个元素后是否能成为单调不降序列或单调不增序列. 对任一序列,先假设其可改造为单调不降序列,若成立则输出YES,不成立再假设其可改造为单调不增序列,若成立则输出 ...
- hdu 5532 Almost Sorted Array(模拟)
Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...
- hdu 5532(最长上升子序列)
Input The first line contains an integer T indicating the total number of test cases. Each test case ...
- 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 / 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 (水题)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
随机推荐
- 有关Flash中与Java调用时候注意的一些事项
1.构建本地拓展的ActionScript库时候要注意SWF文件的版本兼容性: 参考:http://help.adobe.com/zh_CN/air/extensions/WS99209310cacd ...
- javascript表单操作
通过遍历获得列表中被勾选的元素 $("#singcms-push").click(function(){ var id = $("#select-push"). ...
- html中的a标签特例讲解
将自己的博客写成了一个大杂烩了,遇见啥问题就写啥问题.但是当看见自己网页的成品就特别的开心. 还记得看见过的一个故事,说是收费的东西好还是免费的东西好,有一个答案是最让我记忆深刻的.回复的一个答案是: ...
- Struts2配置文件动态传参
两个Action动态传递参数: 1.从一个Action传递到另一个Action如果带有参数那么result中的type属性需要使用redirect 第一个Action代码如下: private Str ...
- JavaScript基础知识复习
1,javascript是基于对象和事件驱动的,并有安全性能的脚本语言: 2,javascript的特点: 1)向HTML中添加交互事件: 2)脚本语言,与java语法类似: 3)解释性语言,边执行边 ...
- bootstrop之模态框关闭
1.js中操作$('#myModal5').map(function() {//用id选择器选中要关闭的模态框 $(this).modal('hide'); //关闭 }); 2.用button在模态 ...
- HDU 5776 sum
猜了一下,发现对了.n>m是一定有解的.所以最多m*m暴力,一定能找到.而T较小,所以能过. #pragma comment(linker, "/STACK:1024000000,10 ...
- 多个git账户生成多份rsa秘钥实现多个账户同时使用配置
下文分享一个多个git账户生成多份rsa秘钥实现多个账户同时使用配置例子了,这个例子非常的好用对于有多个git的朋友有不小的帮助. 使用过git的童鞋应该对id_rsa秘钥不陌生,总得用github吧 ...
- Sublime Text: [Decode error - output not utf-8]
今天编译Python时, 输出窗口信息出现: [Decode error - output not utf-8][Decode error - output not utf-8] 发现是print ...
- Chapter 2 Open Book——22
I dropped my head, letting my hair fall to conceal my face. 我低下了我的头,让我的头发垂下来隐藏我的脸. I was sure,though ...