wzc提醒大家仔细读题真的非常重要!(思维+波峰波谷+细节)

 https://ac.nowcoder.com/acm/contest/12482/F


和cf那题不用在于这个两个人都是往下坡走的。

于是多了一个M和N的特判。同样是一个八字形,但是注意可能还有存在多个V,所以模拟的时候记录一下单个八字形的峰,然后判i-(Max*2-1)

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=1e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
LL a[maxn],l[maxn],r[maxn];
int main(void)
{
  cin.tie(0);std::ios::sync_with_stdio(false);
  LL n;cin>>n;
  for(LL i=1;i<=n;i++) cin>>a[i];
  a[0]=a[n+1]=0;
  for(LL i=1;i<=n;i++){
    if(a[i-1]<a[i]) l[i]=l[i-1]+1;
    else l[i]=1;
  }
  for(LL i=n;i>=1;i--){
    if(a[i]>a[i+1]) r[i]=r[i+1]+1;
    else r[i]=1;
  }
  LL Max=0;
  for(LL i=1;i<=n;i++){
    Max=max(Max,max(l[i],r[i]));
  }
  LL flag=0;///只有相同长度的单个完整峰满足
  LL pos=0;
  for(LL i=1;i<=n;i++){
    if(l[i]==Max&&r[i]==Max) flag++,pos=i;
  }
  if(flag!=1){
    cout<<"0"<<"\n";
    return 0;
  }
  ///  /\
  ///N,W---check只有单个峰,Note V
  LL n1=0;LL w=0;LL v=0;///只有V还可能有多个
  bool ok=1;
  for(LL i=1;i<=n;i++){
     if(l[i]==Max&&r[i]!=Max){
        if(i-(Max-1)*2!=pos){
            ok=0;break;
        }
        if(r[i]==Max&&l[i]!=Max){
            if(i+(Max-1)*2!=pos){
                ok=0;break;
            }
        }
     }
  }
  if(ok) cout<<"1"<<"\n";
  else cout<<"0"<<"\n";
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/115145243
今日推荐