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. 数学#扩展欧几里德 POJ 1061&2115&2891

    寒假做的题了,先贴那时写的代码. POJ 1061 #include<iostream> #include<cstdio> typedef long long LL; usin ...

  2. git config and options core.bare hard

    In Lynda course Building a Web Interface with React.js 003 Using the exercises > git clone --bare ...

  3. Docker技术学习

    原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 .作者信息和本声明.否则将追究法律责任.http://sofar.blog.51cto.com/353572/1598249 貌似Doc ...

  4. chapter9_1 协同程序

    协同程序与线程差不多,也就是一条执行序列:有自己独立的栈.局部变量.指令指针,以及和其他协同程序共享的全局变量和其他大部分东西. 两者区别在于:一个多线程的程序可以同时运行几个线程,而协同程序却需要彼 ...

  5. Android应用测试性能的工具Emmagee,导出文件格式问题分析

    原文引用自:http://www.open-open.com/lib/view/open1367026451078.html Emmagee是监控指定被测应用在使用过程中占用机器的CPU.内存.流量资 ...

  6. Hadoop作业优化

    mapper数量 reduce数量 combiner 中间值压缩 自定义序列 调整shuffle,减少溢出写 关闭推测执行 任务JVM重用 慢启动reduce

  7. iOS 打电话、发短信、发邮件功能

    打电话 方法1 最简单最直接的方式:直接跳到拨号界面 NSURL *url = [NSURL URLWithString:@"tel://10010"]; [[UIApplicat ...

  8. Webdriver控制翻页控件,并实现向前向后翻页功能,附上代码,仅供参考,其他类似日期控件的功能可以自己封装

    新增输入与选择页面的html源码: <div style="margin-top:-60px;" class="modal-content" id=&qu ...

  9. 学习笔记——解释器模式Interpreter

    解释器模式,其实就是编译原理中的语法解释器,如果用在项目中,可以用于实现动态脚本的解析,也就是说项目可以支持用户脚本扩展. 但实际上,这种运行时解释,效率很慢,如果不是很需要的话,不建议使用. 一种简 ...

  10. # Linux Whois3获取 运营商信息

    Linux Whois3获取 运营商信息 APNIC是管理亚太地区IP地址分配的机构,它有着丰富准确的IP地址分配库,同时这些信息也是对外公开的,并提供了一个查询工具,下面就让我们看看如何在Linux ...