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. spring mvc 自定义转换器

    <!-- 注册转化器 --> <mvc:annotation-driven conversion-service="conversionService" /> ...

  2. 读取Excel文件中的单元格的内容和颜色

    怎样读取Excel文件中的单元格的内容和颜色 先创建一个Excel文件,在A1和A2中随意输入内容,设置A1的字体颜色为红色,A2的背景为黄色.需要 using Excel = Microsoft.O ...

  3. C语言之字节对齐

    在C语言编程中,有时为了达到减少运行的时间的目的,需要浪费一些空间:而有时为了节省空间,使它的运行时间增长.而字节对齐则是为了访问效率,用空间换取时间. 要掌握字节对齐,首先得明确一下四个概念: 1. ...

  4. WEBUS2.0 In Action - 搜索操作指南 - (3)

    上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...

  5. BZOJ 2429 聪明的猴子

    kruskal. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...

  6. Spring读取配置文件的几种方式

    import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; imp ...

  7. php 格式化数字 位数不足前面加0补足

    本文引用自 http://www.fengfly.com/plus/view-62827-1.html 补0: <?php $var = sprintf("%03d", 12 ...

  8. switchover步骤切换

    主库 alter system switch logfile; alter system set log_archive_dest_state_2='defer'; select switchover ...

  9. 使用Jquery Mobile设计Android通讯录

    本系列教程将指导大家一步步使用Jquery Mobile设计一个Android的通讯录应用.其中在应用的界面部分,将使用jQuery Mobile框架,并且会指导大家如何使Android中提供的web ...

  10. 利用命令控制台cmd进入某个硬盘的某个文件夹的命令是什么?

    在命令行窗口中输入F:后回车就可以切换到F盘,如果想查看F盘的内容,可以再输入dir后回车 (输入“F”后要再输入一个“ :”再回车才行哦)