http://acm.hdu.edu.cn/showproblem.php?pid=5532

 题目大意:
给你一个不规则的序列,问是否能够通过删除一个元素使其成为一个有序的序列(递增或递减(其中相邻的元素可以相等))
 
将序列里分成两种可能讨论,该序列除了一个元素之外要么递增要么递减,只需满足一个即可
 
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm> using namespace std; const int N = 1e5 + ; int a[N], f, n; void Increase()
{
int num = , index;
for(int i = ; i < n ; i++)
{
if(a[i - ] > a[i])
{
num++;
index = i;
}
}
if(num == )
f = ;
else if(num == )
{//这些情况的例子 3 1 2 3 /*******/ 1 2 4 4 /*********/ 1 1 2 1 4 /*****/ 1 2 3 4
if(index == || a[index - ] <= a[index + ] || a[index - ] <= a[index] || index == n - )
f = ;
}//红色部分为index标记的元素
} void Decrease()
{
int index, num = ;
for(int i = ; i < n ; i++)
{
if(a[i - ] < a[i])
{
num++;
index = i;
}
}
if(num == )
f = ;
else if(num == )
{
if(index == || a[index - ] >= a[index + ] || a[index - ] >= a[index] || index == n - )
f = ;
}
} int main()
{
int t;
scanf("%d", &t);
while(t--)
{
f = ;
scanf("%d", &n);
for(int i = ; i < n ; i++)
scanf("%d", &a[i]);
Increase();
if(f == )//如果满足递增序列,即可得出结果
{
printf("YES\n");
continue;
}
Decrease();//否则判断其是否满足递减序列
if(f == )
printf("YES\n");
else
printf("NO\n");
}
return ;
}

hdu 5532 Almost Sorted Array的更多相关文章

  1. hdu 5532 Almost Sorted Array(模拟)

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

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

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

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

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

  4. hdu 5532 Almost Sorted Array (水题)

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

  5. hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列

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

  6. HDU - 5532 Almost Sorted Array (最长非严格单调子序列)

    We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, sele ...

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

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

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

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

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

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

随机推荐

  1. NET垃圾回收机制【Copy By Internet】

    尽管在.NET framework下我们并不需要担心内存管理和垃圾回收(Garbage Collection),但是我们还是应该了解它们,以优化我们的应用程序.同时,还需要具备一些基础的内存管理工作机 ...

  2. Tomcat,Jboss,Glassfish等web容器比较选型

    概述 Web容器是一种服务调用的规范,J2EE运用了大量的容器和组件技术来构建分层的企业应用.在J2EE规范中,相应的有WEB Container和EJB Container等. Web容器给处于其中 ...

  3. POJ 3692 Kindergarten (补图是二分图的最大团问题)

    题意 幼稚园里有m个男孩和n个女孩(m.n范围都是[1,200]),男孩之间相互认识,女孩之间也相互认识,另外有部分男孩和女孩也认识.现在要举办一个活动,选取一些同学,要求所有选取的同学之间两两相互认 ...

  4. BPMN这点事-BPMN扩展元素

    什么是BPMN扩展元素?我们为什么要从BPMN元素中界定出一个扩展元素的子集?BPMN扩展元素是我们平时使用频率不高的BPMN元素,这些元素更多的面向开发人员而不是业务人员,它们强调流程执行的细节,例 ...

  5. 【转】vim - tab变空格

    vim中将tab自动转换成空格 在vim中,有时需要将tab转换成space.使用ret命令(replace tab).[range]ret[ab]! [new-tabstop] 举例:将第一行到文件 ...

  6. SAS使用SPD引擎并报Encoding错误

     ERROR: Unable to open data file because its file encoding differs from the SAS session encoding and ...

  7. Spring cron 表达式

    前言: 最近做的项目有用到定时器,每周只在特定时间运行一次,考虑到Spring Task的简单易用性,就果断选择了,我是配置在配置文件里面,没有用注解@Scheduled,推荐配置,注解虽方便,但更改 ...

  8. 查看Linux下端口占用情况的命令

    在使用Linux系统的过程中,有时候会遇到端口被占用而导致服务无法启动的情况.比如HTTP使用80端口,但当启动Apache时,却发现此端口正在使用. 这种情况大多数是由于软件冲突.或者默认端口设置不 ...

  9. 【转】Xcode添加静态库以及编译选项配置常见问题

    原文网址:http://www.cnblogs.com/Quains/p/3276425.html 一,Xcode编译出现Link错误,出现"duplicate symbols for ar ...

  10. JBPM4入门——5.流程定义的发布、查询、删除

    本博文只是简要对JBPM4进行介绍,如需更详细内容请自行google 链接: JBPM入门系列文章: JBPM4入门——1.jbpm简要介绍 JBPM4入门——2.在eclipse中安装绘制jbpm流 ...