HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array
Almost Sorted Array
We say an array is sorted if its elements are in non-decreasing order or non-increasing order. We say an array is almost sorted if we can remove exactly one element from it, and the remaining array is sorted. Now you are given an array a1
,a
2
,…,a
n
, is it almost sorted?
indicating the total number of test cases. Each test case starts with an integer n
in one line, then one line with n
integers a1
,a
2
,…,a
n
.
1≤T≤2000
2≤n≤105
1≤ai
≤10
5
There are at most 20 test cases with n>1000
.
3
2 1 7
3
3 2 1
5
3 1 4 1 5
YES
NO
///
#include<bits/stdc++.h>
using namespace std ;
typedef long long ll;
#define mem(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,127,sizeof(a));
#define inf 1000000007
inline ll read()
{
ll x=,f=;char ch=getchar();
while(ch<''||ch>''){
if(ch=='-')f=-;ch=getchar();
}
while(ch>=''&&ch<=''){
x=x*+ch-'';ch=getchar();
}return x*f;
}
//**************************************** #define maxn 100000+5
int a[maxn],n;
int main(){
int T=read();
while(T--){
scanf("%d",&n);int flag=;
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
int res=,fall=;
for(int i=;i<=n;i++){
if(i->=&&a[i]>a[i-])res++;
else if(i->=&&a[i]<a[i-])fall++;
}
// cout<<fall<<" "<<res<<endl;
for(int i=;i<=n;i++){
int t1=res,t2=fall;
if(i->=&&a[i]>a[i-]){
res--;
}
else if(i->=&&a[i]<a[i-]){
fall--;
}
if(i+<=n&&a[i]>a[i+]){
fall--;
}
else if(i+<=n&&a[i]<a[i+]){
res--;
}
if(i->=&&i+<=n){
if(a[i-]<a[i+]){
res++;
}else if(a[i-]>a[i+])fall++;
}
if(fall==||res==){
flag=;break;
}
res=t1;fall=t2;
}
if(flag){
cout<<"YES"<<endl;
}
else cout<<"NO"<<endl; }
return ;
}
代码
HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array的更多相关文章
- 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 ...
- 2015ACM/ICPC亚洲区长春站 H hdu 5534 Partial Tree
Partial Tree Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)To ...
- 2015ACM/ICPC亚洲区长春站 B hdu 5528 Count a * b
Count a * b Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Tot ...
- 2015ACM/ICPC亚洲区长春站 L hdu 5538 House Building
House Building Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others) ...
- 2015ACM/ICPC亚洲区长春站 J hdu 5536 Chip Factory
Chip Factory Time Limit: 18000/9000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)T ...
- 2015ACM/ICPC亚洲区长春站 G hdu 5533 Dancing Stars on Me
Dancing Stars on Me Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Ot ...
- 2015ACM/ICPC亚洲区长春站 E hdu 5531 Rebuild
Rebuild Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- 2015ACM/ICPC亚洲区长春站 A hdu 5527 Too Rich
Too Rich Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total ...
- HDU-5532//2015ACM/ICPC亚洲区长春站-重现赛-F - Almost Sorted Array/,哈哈,水一把区域赛的题~~
F - Almost Sorted Array Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & ...
随机推荐
- python--9、进程池
concurrent.futures模块 进程池中的进程是固定的,若是池中有任务结束后,等待的任务进来后由空闲的进程来处理. 导入方法三连发: from 标题的模块 import 如下:Process ...
- SAS进阶《深入解析SAS》之对多数据集的处理
SAS进阶<深入解析SAS>之对多数据集的处理 1. 数据集的纵向串接: 数据集的纵向串接指的是,将两个或者多个数据集首尾相连,形成一个新的数据集. 据集的横向合并: 数据集的横向合并,指 ...
- Android仿今日头条和知乎等App顶部滑动导航实现代码分析及源码下载
一.本文所涉及到的知识点 源码下载 二.目标 通过利用ViewPager+FragmentStatePagerAdapter+TabLayout 实现顶部滑动效果,如图: 三.知识点讲解 1.View ...
- sublime之markdown快捷键
目录 sublime 快捷键 markdown技能 sublime 快捷键 ctrl + shift + p 进入命令面板 package install 进入下载仓库 ctrl + alt + O ...
- Discuz! X3.1云平台QQ互联的Unknown column 'conuintoken' in 'field list' 解决办法
http://www.discuz.net/thread-3482497-1-1.html 由于程序安装默认数据表的结构和QQ互联数据表结构不同,安装Discuz! X3.1和升级Discuz! X3 ...
- day03-执行python方式、变量及数据类型简介
目录 执行Python程序的两种方式 1. 第一种:交互式 2. 第二种:命令式 3. Python执行程序的三个阶段 变量 变量 什么是变量 Python中的变量 变量名的命名规范 内存管理 定义变 ...
- 【原】PHPExcel导出Excel
1.引入相关公共库PHPExcel 2.编写公共函数 public function exportExcel($excelTitle,$data,$filename='',$column_width= ...
- Day 12 字符串和正则表达式
使用正则表达式 正则表达式相关知识 在编写处理字符串的程序或网页时,经常会有查找符合某些复杂规则的字符串的需要,正则表达式就是用于描述这些规则的工具,换句话说正则表达式是一种工具,它定义了字符串的匹配 ...
- CentOS安装Docker-ce并配置国内镜像
前提条件 1.系统.内核 CentOS7 要求64位系统.内核版本3.10以上 CentOS6 要求版本在6.5以上,系统64位.内核版本2.6.32-431以上 查看内核版本号 uname -r # ...
- Highcharts教程--把js代码从html中抽离出来,放到单独的一个js文件中。由html页面调用
1.html页面写法 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&quo ...