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的更多相关文章

  1. hdu 5532 Almost Sorted Array

    http://acm.hdu.edu.cn/showproblem.php?pid=5532  题目大意: 给你一个不规则的序列,问是否能够通过删除一个元素使其成为一个有序的序列(递增或递减(其中相邻 ...

  2. hdu 5532 (LIS) Almost Sorted Array

    http://acm.hdu.edu.cn/showproblem.php?pid=5532 题意大致是一组数中去掉一个数后问剩下的数是否构成非严格单调序列 正反各跑一遍最长非严格连续子序列,存在长度 ...

  3. 【HDU 5532 Almost Sorted Array】水题,模拟

    给出一个序列(长度>=2),问去掉一个元素后是否能成为单调不降序列或单调不增序列. 对任一序列,先假设其可改造为单调不降序列,若成立则输出YES,不成立再假设其可改造为单调不增序列,若成立则输出 ...

  4. hdu 5532 Almost Sorted Array(模拟)

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

  5. hdu 5532(最长上升子序列)

    Input The first line contains an integer T indicating the total number of test cases. Each test case ...

  6. HDU 5532 Almost Sorted Array (最长非递减子序列)

    题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...

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

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

  8. HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array

    Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...

  9. hdu 5532 Almost Sorted Array (水题)

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

随机推荐

  1. HDU_1245_Saving James Bond_最短路

    题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=1245 题意:给一个已知直径的圆形岛,然后岛的附近是湖,湖里有一些点,以坐标的形式给出,最外层是矩形的终 ...

  2. 如何安装VM Tool软件包

    在linux下,我们想把原windows操作系统下的一些文件拷入到新linux系统中,在windows下对文件(夹)进行复制,在linux下无法进行粘贴,何故?这是因为新装的linux操作系统未安装V ...

  3. HDU 2514 Another Eight Puzzle(DFS)

    题目链接 Problem Description Fill the following 8 circles with digits 1~8,with each number exactly once ...

  4. PHP下用正则表达式分割preg_split、替换reg_replace、匹配preg_match_all等出现乱码的解决方法

    操作前声明操作字符的编码: mb_regex_encoding('utf-8'); $arr = preg_split('/[\n,]/u',$data['name'] ,0, PREG_SPLIT_ ...

  5. 比较不熟的JavaScript点滴,慢慢前行,附带简单复杂化的php小计算器一份

    interface.php <html> <head> <meta charset="utf-8" /> <title>这是一个简单 ...

  6. Objective-C中的instancetype与id的区别

    一.什么是instancetype instancetype是clang 3.5开始,clang提供的一个关键字,表示某个方法返回的未知类型的Objective-C对象.我们都知道未知类型的的对象可以 ...

  7. 杭电三部曲一、基本算法;19题 Cow Bowling

    Problem Description The cows don't use actual bowling balls when they go bowling. They each take a n ...

  8. 安卓手机微信页面position: fixed位置错误

    今天做项目的时候发现动用position: fixed做弹窗时,用margin-top:50%这样外边距来响应式的控制位置时,在微信里打开页面的弹窗,弹窗在手机上显示的位置和实际上在手机上的位置不一样 ...

  9. 使用计算监控(Using computed observables)

    计算监控(Computed Observables) 如果有两个监控属性firstName, lastName,此时我们要显示full name,我们要怎么办呢? 这时,可以创建一个computed ...

  10. zabbix3.2在lamp环境安装

    zabbix官网下载zabbix-3.2.1.tar.gz wget http://jaist.dl.sourceforge.net/project/zabbix/ZABBIX%20Latest%20 ...