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. CSS 中浮动的使用

    float none 正常显示 left 左浮动 right 右浮动 clear none 允许两边浮动 left 不允许左边浮动 right 不允许右边浮动 both 不允许两边浮动 <!DO ...

  2. CSS3之边框样式(动画过渡)

    简述 CSS3中transition属性定义了过渡,我们可以使用它来辅助我们实现一个边框样式的动画过渡. 简述 transition 定义和用法 语法 实现 效果 源码 transition 定义和用 ...

  3. POJ 2236 (简单并查集) Wireless Network

    题意: 有n个电脑坏掉了,分别给出他们的坐标 有两种操作,可以O x表示修好第x台电脑,可以 S x y表示x y是否连通 两台电脑的距离不超过d便可连通,两台电脑是连通的可以直接连通也可以间接通过第 ...

  4. POJ 2594 Treasure Exploration (可相交最小路径覆盖)

    题意 给你张无环有向图,问至少多少条路径能够覆盖该图的所有顶点--并且,这些路径可以有交叉. 思路 不是裸的最小路径覆盖,正常的最小路径覆盖中两个人走的路径不能有重复的点,而本题可以重复. 当然我们仍 ...

  5. 韦东山驱动视频笔记——3.字符设备驱动程序之poll机制

    linux内核版本:linux-2.6.30.4 目的:我们在中断方式的按键应用程序中,如果没有按键按下,read就会永远在那等待,所以如果在这个程序里还想做其他事就不可能了.因此我们这次改进它,让它 ...

  6. == Rickard Oberg & TheServerSide

    看了Hani Suleiman和Rickard Oberg ,发现其实每个所谓的权威都应该有被质疑的绝对,可能往往权威会令人觉得理所应当

  7. 【转】安装Django

    原文网址:http://www.crifan.com/record_install_django/ 1.参考Quick install guide,最终找到下载的地址: http://bitnami. ...

  8. Android 高仿豌豆荚 一键安装app 功能 实现

    以往我们那些应用市场 帮我们安装app的时候  我们都得点确定,当然你如果 root 以后 不用点确定 也能自动安装了,后来豌豆荚 推出了一个功能 非root的手机也能不点确定 直接帮你安装好.(如果 ...

  9. Spring aop 实现异常拦截

    使用aop异常挂载功能可以统一处理方法抛出的异常,减少很多重复代码,实现如下: 1.实现ThrowAdvice public class ExceptionHandler implements Thr ...

  10. 嵌入式 hi3518平台增加路由代码

    <span style="font-family:Courier New;"> /********************************** (C) COPY ...