hdu 5532 Almost Sorted Array
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的更多相关文章
- hdu 5532 Almost Sorted Array(模拟)
Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, ...
- HDU 5532 Almost Sorted Array (最长非递减子序列)
题目链接 Problem Description We are all familiar with sorting algorithms: quick sort, merge sort, heap s ...
- HDU 5532——Almost Sorted Array——————【技巧】
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5532 Almost Sorted Array (水题)
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- hdu 5532 Almost Sorted Array nlogn 的最长非严格单调子序列
Almost Sorted Array Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- HDU - 5532 Almost Sorted Array (最长非严格单调子序列)
We are all familiar with sorting algorithms: quick sort, merge sort, heap sort, insertion sort, sele ...
- 【HDU 5532 Almost Sorted Array】水题,模拟
给出一个序列(长度>=2),问去掉一个元素后是否能成为单调不降序列或单调不增序列. 对任一序列,先假设其可改造为单调不降序列,若成立则输出YES,不成立再假设其可改造为单调不增序列,若成立则输出 ...
- 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 ...
- HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array
Almost Sorted Array Problem Description We are all familiar with sorting algorithms: quick sort, mer ...
随机推荐
- spring mvc 自定义转换器
<!-- 注册转化器 --> <mvc:annotation-driven conversion-service="conversionService" /> ...
- 读取Excel文件中的单元格的内容和颜色
怎样读取Excel文件中的单元格的内容和颜色 先创建一个Excel文件,在A1和A2中随意输入内容,设置A1的字体颜色为红色,A2的背景为黄色.需要 using Excel = Microsoft.O ...
- C语言之字节对齐
在C语言编程中,有时为了达到减少运行的时间的目的,需要浪费一些空间:而有时为了节省空间,使它的运行时间增长.而字节对齐则是为了访问效率,用空间换取时间. 要掌握字节对齐,首先得明确一下四个概念: 1. ...
- WEBUS2.0 In Action - 搜索操作指南 - (3)
上一篇:WEBUS2.0 In Action - 搜索操作指南(2) | 下一篇:WEBUS2.0 In Action - 搜索操作指南(4) 3. 评分机制 (Webus.Search.IHitSc ...
- BZOJ 2429 聪明的猴子
kruskal. #include<iostream> #include<cstdio> #include<cstring> #include<algorit ...
- Spring读取配置文件的几种方式
import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileReader; imp ...
- php 格式化数字 位数不足前面加0补足
本文引用自 http://www.fengfly.com/plus/view-62827-1.html 补0: <?php $var = sprintf("%03d", 12 ...
- switchover步骤切换
主库 alter system switch logfile; alter system set log_archive_dest_state_2='defer'; select switchover ...
- 使用Jquery Mobile设计Android通讯录
本系列教程将指导大家一步步使用Jquery Mobile设计一个Android的通讯录应用.其中在应用的界面部分,将使用jQuery Mobile框架,并且会指导大家如何使Android中提供的web ...
- 利用命令控制台cmd进入某个硬盘的某个文件夹的命令是什么?
在命令行窗口中输入F:后回车就可以切换到F盘,如果想查看F盘的内容,可以再输入dir后回车 (输入“F”后要再输入一个“ :”再回车才行哦)