D. Let‘s Go Hiking(思维+波峰波谷)

https://codeforces.com/contest/1496/problem/D


思路:

就是模拟找关系吧..画一大堆凹凸的波峰波谷找规律。

1代表递增,2代表递减

1 1 1 1 1 2 2 这种怎么选都是先手输

2 2 1 1 1 1 1 同理。

所以唯一可能获胜的就是

1 1 1  2 2 2 且左右两边的长度相等为奇数,这样才可能相等。当然,这样的长度个数只能是2个,当大于2个的时候,后手总能胜利

1 1 1 2 2 2  1 1 1 (N形状)

1 1 1 2 2 2  1 1 1  2 2 2 (M形状)

另外牛客昨天的农林场有一题和这个类似,只是改了一个条件。多了一个特判的地方。

#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];
LL 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]>a[i-1]) 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;
  LL cnt=0;
  bool flag=1;///判有没有左右两边相同长度且长度最大的数量
  for(LL i=1;i<=n;i++){
     if(Max<max(l[i],r[i])){///找一侧长度最大的
        Max=max(l[i],r[i]);
        cnt=0;
        flag=0;
        if(l[i]==r[i]&&Max==l[i]&&(l[i]&1) ) flag=1,cnt++;
     }
     else if(Max==max(l[i],r[i])){
        cnt++;
     }
  }
  if(flag==1){
    if(cnt>=2){
        cout<<"0"<<"\n";
    }
    else cout<<"1"<<"\n";
  }
  else if(flag==0){
    cout<<"0"<<"\n";
  }
return 0;
}

猜你喜欢

转载自blog.csdn.net/zstuyyyyccccbbbb/article/details/115102533