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. ckeditor上传图片的注意点

    1.要在 ckeditor的  config.js 文件中加上 CKEDITOR.editorConfig = function( config ) { config.filebrowserImage ...

  2. 遍历(二)javascript的Foreach语法

    原文:http://www.cnblogs.com/Fskjb/archive/2011/03/26/1996165.html 首先,虽然叫foreach语法但关键字还是用for哦,这个语法只是对平时 ...

  3. ESFramework 4.0 性能测试

    本实验用于测试ESFramework服务端引擎的性能,测试程序使用ESFramework 4.0版本. 一.准备工作 测试的机器总共有3台,都是普通的PC,一台作为服务器,两台作为客户端. 作为服务器 ...

  4. C语言 - 预编译

    1.#ifdef 实现 与 或#if (defined SIMULATION) && (defined _FMM_LOG)#endif #if (!defined A) || (!de ...

  5. 小心DLL链接静态库时的内存错误

    本文转自http://www.bennychen.cn/2010/09/%E5%B0%8F%E5%BF%83dll%E9%93%BE%E6%8E%A5%E9%9D%99%E6%80%81%E5%BA% ...

  6. mvc路由参数注解

    routes.IgnoreRoute("{resource}.axd/{*pathInfo}"); //过滤掉禁止访问的路由 routes.MapRoute( name: &quo ...

  7. C++ inline和#define宏的区别

    (1)什么是内联函数? 内联函数是指那些定义在类体内的成员函数,即该函数的函数体放在类体内. (2)为什么要引入内联函数?当然,引入内联函数的主要目的是:解决程序中函数调用的效率问题.另外,前面我们讲 ...

  8. C++ 类的继承、虚拟继承、隐藏、占用空间

    主函数: #include <iostream> #include "test.h" #include "testfuc.h" using name ...

  9. C/C++语言的标准库函数malloc/free与运算符new/delete的区别

    概括地说 1.malloc与free是C++/C的标准库函数,new/delete是C++的运算符,它们都可用于申请动态内存和释放内存. 2.对于非内部数据类型的对象而言,只用malloc/free无 ...

  10. 项目管理实践【三】每日构建【Daily Build Using CruiseControl.NET and MSBuild】

    在上一篇项目管理实践教程二.源代码控制[Source Control Using VisualSVN Server and TortoiseSVN]中我们已经讲解了如何使用TortoiseSVN和Vi ...