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 & ...
随机推荐
- linq 分组
var data = from r in listRecords group r by new { r.CampaignId, r.CityId, r.Gift_DistributorId, r.Pr ...
- StackOverflowError&OutOfMemoryError区别
在Java虚拟机规范中,针对内存分配规定两种异常状况,即StackOverflowError和OutOfMemoryError. StackOverflowError:当线程请求的内存大小大于所配置的 ...
- Angular——todos案例
基本介绍 (1)视图绑定两个数组,分别对应未完成和已完成 (2)数组的删除splice(),数组的追加push() 基本使用 <!DOCTYPE html> <html lang=& ...
- [Windows Server 2003] 安装SQL Server 2005
★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:安装SQL S ...
- 删除ListView item数据 页面不刷新
最近碰到一个匪夷所思的事情.就是我删除listView中一条item数据 网络请求成功了 但是页面不成功,一番折腾 ,找到问题 ,原来我给item 添加了北京点击事假,又给listView 被禁设置 ...
- HDU_1502_dp
Regular Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Tot ...
- java_io学习_编码
package io; public class encodingDemo{ public static void main(String[] args) throws Exception{ // T ...
- IOS7 APP 升级的10个TIP 建议
There is no way to preserve the iOS 6 style status bar layout. The status bar will always overlap yo ...
- jdbcUrl is required with driverClassName错误解决
jdbcUrl is required with driverClassName springboot2.0配置多数据源: spring.datasource.primary.url=jdbc:mys ...
- vue中fetch请求
1. 请求方式:get 请求参数:menuName 返回的结果:data created(){ this._initPageData() }, methods:{ _initPageData(){ f ...