标签:
///1085422276 #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=0,f=1;char ch=getchar(); while(ch<‘0‘||ch>‘9‘){ if(ch==‘-‘)f=-1;ch=getchar(); } while(ch>=‘0‘&&ch<=‘9‘){ x=x*10+ch-‘0‘;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=0; for(int i=1;i<=n;i++){ scanf("%d",&a[i]); } int res=0,fall=0; for(int i=1;i<=n;i++){ if(i-1>=1&&a[i]>a[i-1])res++; else if(i-1>=1&&a[i]<a[i-1])fall++; } // cout<<fall<<" "<<res<<endl; for(int i=1;i<=n;i++){ int t1=res,t2=fall; if(i-1>=1&&a[i]>a[i-1]){ res--; } else if(i-1>=1&&a[i]<a[i-1]){ fall--; } if(i+1<=n&&a[i]>a[i+1]){ fall--; } else if(i+1<=n&&a[i]<a[i+1]){ res--; } if(i-1>=1&&i+1<=n){ if(a[i-1]<a[i+1]){ res++; }else if(a[i-1]>a[i+1])fall++; } if(fall==0||res==0){ flag=1;break; } res=t1;fall=t2; } if(flag){ cout<<"YES"<<endl; } else cout<<"NO"<<endl; } return 0; }
HDU 5532 / 2015ACM/ICPC亚洲区长春站 F.Almost Sorted Array
标签:
原文地址:http://www.cnblogs.com/zxhl/p/4977481.html