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 & ...
随机推荐
- ubuntu 安装redis以及phpredis
一.安装redis 1. 去百度搜索 redis,然后去靠谱的地方下载最新的redisxxx.tar.gz 2. 解压后,sudo make 3. sudo make install 4. //安装完 ...
- SQL练习题_用户购买收藏记录合并(拼多多)
目录 拼多多笔试题0805_统计用户数据 笔试题描述 表格构建 数据观察 题目分析 一.合并表格 二.CASE表示(0,1) 三.同理复制FORK表 题目解答 拼多多笔试题0805_统计用户数据 笔试 ...
- 移动web——touch事件介绍
基本概念 1.在移动web端点击事件或者滑动屏幕.捏合等动作都是由touchstar.touchmove.touchend这三个事件组合在一起使用的 2.click事件在移动端会有0.2秒的延迟,下面 ...
- 一个例子理解ES6的yield关键字
yield是什么 yield是ES6的新关键字,使函数暂停执行. 一个简单例子 function *countASb() { console.log('Show0:'); var a1 = yield ...
- ABP初始化
默认认为你手中已经有abp-zero项目,当前4.6.0 angularJS切换到jquery 运行项目,初始化是跳转到~/App/common/views/layout/layout.cshtml, ...
- PAC代理语法含义与书写规范
一直以来使用ShadowSocksFQ,基本上默认的PAC代理模式己能满足所需,实在个别pac不方便的就转成用全局代理模式也能愉快FQ. 只是最近学习前端的知识,需要FQ访问 MDN web docs ...
- php第十五节课
租房表 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3. ...
- 初学者对ASCII编码、Unicode编码、UTF-8编码的理解
最早的计算机在设计时采用8个比特(bit)作为一个字节(byte),所以,一个字节能表示的最大的整数就是 255(二进制 11111111=十进制 255),如果要表示更大的整数,就必须用更多的字节. ...
- 02. 爬取get请求的页面数据
目录 02. 爬取get请求的页面数据 一.urllib库 二.由易到难的爬虫程序: 02. 爬取get请求的页面数据 一.urllib库 urllib是Python自带的一个用于爬虫的库,其主要作用 ...
- 编译OpenWrt失败
/home/fly/work_dir/OpenWrt-SDK/OpenWrt-Test/trunk/scripts/download.pl "/home/fly/work_dir/OpenW ...