CodeForces 1496D :Let‘s Go Hiking 博弈

传送门

题目描述

有一个长度为 n n n的排列 p n p_{n} pn,首先 Q i n g s h a n Qingshan Qingshan选择一个数 a a a D a n i e l Daniel Daniel选择另一个数 b b b
Q i n g s h a n Qingshan Qingshan先手,移动到相邻的位置 a ′ a' a ( p a ′ < p a , a ′ ≠ b ) (p_{a'} < p_{a},a' \neq b) (pa<pa,a=b),然后 D a n i e l Daniel Daniel移动到相邻的位置 b ′ b' b ( p b ′ > p b , b ′ ≠ a ′ ) (p_{b'} > p_{b},b' \neq a') (pb>pb,b=a)
问有多少位置可以让 Q i n g s h a n Qingshan Qingshan必胜

分析

首先我们可以确定, Q i n g s h a n Qingshan Qingshan一定要选择一个波峰,因为他可以从两边走,否则就只能走一边, D a n i e l Daniel Daniel可以将 Q i n g s h a n Qingshan Qingshan堵死
然后我们得确定,最长的波峰只能有一个,因为如果有两个的话, Q i n g s h a n Qingshan Qingshan走一个, D a n i e l Daniel Daniel走一个,因为 D a n i e l Daniel Daniel是后手,所以 D a n i e l Daniel Daniel获胜
一个波峰有两边可以下降,如果两边下降长度不一样,那么我们一定可以在长侧选择一个长度为偶数的位置,这个时候 Q i n g s h a n Qingshan Qingshan有两种选择,走长侧的话因为是先手所以必败,选短侧的话长度肯定是小于或者等于长侧,所以必败
所以需要波峰两边长度相同,并且长度是奇数才能保证必胜,所以最后答案只有两种情况, 0 0 0 1 1 1

代码

#pragma GCC optimize(3)
#include <bits/stdc++.h>
#define debug(x) cout<<#x<<":"<<x<<endl;
#define dl(x) printf("%lld\n",x);
#define di(x) printf("%d\n",x);
#define _CRT_SECURE_NO_WARNINGS
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
const int INF = 0x3f3f3f3f;
const int N = 2e5 + 10;
const ll mod= 1000000007;
const double eps = 1e-9;
const double PI = acos(-1);
template<typename T>inline void read(T &a){
    
    char c=getchar();T x=0,f=1;while(!isdigit(c)){
    
    if(c=='-')f=-1;c=getchar();}
while(isdigit(c)){
    
    x=(x<<1)+(x<<3)+c-'0';c=getchar();}a=f*x;}
int gcd(int a,int b){
    
    return (b>0)?gcd(b,a%b):a;}
int a[N];
int l[N],r[N];
int n;

int main(){
    
    
    read(n);
    for(int i = 1;i <= n;i++) read(a[i]);
	l[1] = 1,r[n] = 1;
    for(int i = 2;i <= n;i++){
    
    
    	if(a[i] > a[i - 1]) l[i] = l[i - 1] + 1;
    	else l[i] = 1;
    }
    for(int i = n - 1;i;i--){
    
    
    	if(a[i] > a[i + 1]) r[i] = r[i + 1] + 1;
    	else r[i] = 1;
    }
    int mx = 0,cnt = 0,id = 0;
    for(int i = 1;i <= n;i++){
    
    
    	if(mx == max(l[i],r[i])){
    
    
    		cnt++;
    	}
    	else if(mx < max(l[i],r[i])){
    
    
    		mx = max(l[i],r[i]);
    		id = i;
    		cnt = 1;
    	}
    }
    if(l[id] != r[id] || (mx & 1) == 0 || cnt > 1) puts("0");
    else puts("1");
    return 0;
}

/**
*  ┏┓   ┏┓+ +
* ┏┛┻━━━┛┻┓ + +
* ┃       ┃
* ┃   ━   ┃ ++ + + +
*  ████━████+
*  ◥██◤ ◥██◤ +
* ┃   ┻   ┃
* ┃       ┃ + +
* ┗━┓   ┏━┛
*   ┃   ┃ + + + +Code is far away from  
*   ┃   ┃ + bug with the animal protecting
*   ┃    ┗━━━┓ 神兽保佑,代码无bug 
*   ┃        ┣┓
*    ┃        ┏┛
*     ┗┓┓┏━┳┓┏┛ + + + +
*    ┃┫┫ ┃┫┫
*    ┗┻┛ ┗┻┛+ + + +
*/


猜你喜欢

转载自blog.csdn.net/tlyzxc/article/details/114969188