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 ...
随机推荐
- 使用git submodule管理一个需要多个分立开发或者第三方repo的项目
在项目开发中,特别是web前端开发中,有非常多的开源第三方library,我们希望引用他们,同时也希望能够方便地保持这些第三方 开源repo的更新.另外一方面如果我们自己在开发一个网站的项目,这个项目 ...
- 在 VC6 中使用 GdiPlus-使用
下面用 VC6 来写一个 GdiPlus 的 Demo 工程 Step1:新建一个名为 Demo_GdiPlus 的 MFC AppWizard(exe) 工程 操作步骤:(1)主菜单File-> ...
- POJ 1201 Intervals (差分约束,最短路)
题意: 有一个集合Z,其元素都是整整数,但是数量未知.现有n个约束,形如 [a,b]=c 表示整数区间[a,b]中有c个元素在Z中出现.问集合Z最小可能含多少个元素? 思路: 对于所给的区间 cnt[ ...
- [转载] 问题解决:FFmpeg视频编解码库,无法解析的外部信号
在编译FFmpeg相关项目时,可能会出现: error LNK2019: 无法解析的外部符号 "int __cdecl avpicture_fill(struct AVPicture *,u ...
- OpenVz一键安装openvpn
# !/bin/sh # OPENVPN SERVER CONFIGURATION echo "####################################" echo ...
- 2015年目标一:学习掌握python
俗话说:凡事预则立,不预则废.又到新的一年,给自己确定第一个目标:学习python.掌握python基本用法.其实2014年已经断断续续接触过python,但一直是不系统地在学习,而且基本上没有把py ...
- PhoneGap与Jquery Mobile结合开发android应用配置
由于工作需要,用到phonegap与jquery moblie搭配,开发android应用程序. 这些技术自己之前也都没接触过,可以说是压根没听说过,真是感慨,在开发领域,技术日新月异,知识真是永远学 ...
- bjfu1299 stl使用
题目超简单,我写解题报告是因为我的代码用了些STL,使代码很简洁. * * Author : ben */ #include <cstdio> #include <cstdlib&g ...
- .net core 使用
在本机上安装了 visual studio 2015后,还要安装 DotNetCore.1.0.1-VS2015Tools.Preview2.0.3.exe 才能编译 .net core 的代码.不然 ...
- ajax实现md5加密
一个asp.net ajax例子,使用jquery,实现md5加密..NET 4.0,Visual Studio 2010以上.效果体验:http://tool.keleyi.com/t/md5.ht ...