题意
给你n堆石头,L和K两个人玩一个游戏:每个人轮流拿从一堆石头中拿一颗石头出来,但是在整个过程中要保证相邻的石头不相等,最后谁拿不了了谁输。L先拿。现在给你这n堆石头,问你谁能获胜?
思路
因为相邻的数不相同,那么一定会有某一个值小于两遍的情况,那么这个值就可以减少为0,同时以这个点往两边递增为能变成的最小的情况,那么计算新数组和原数组的差值即可,如果为奇数就是L赢,否则是K赢。(具体处理看代码)
代码
#include<cstdio>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include<vector>
#include<queue>
#include<map>
#define sc_int(x) scanf("%d", &x)
#define sc_ll(x) scanf("%lld", &x)
#define pr_ll(x) printf("%lld", x)
#define pr_ll_n(x) printf("%lld\n", x)
#define pr_int_n(x) printf("%d\n", x)
#define ll long long
using namespace std;
const int N=1000000+100;
int n ,m,h;
int s[N],cnt[N];
void df1(int i,int x)
{
if(i<=1)return ;
if(s[i]<s[i-1])
{
cnt[i-1]=max(x++,cnt[i-1]);//这里如果有更大的要取那么就应该取更大的
df1(i-1,x);
}
}
void df2(int i,int x)
{
if(i>=n)return ;
if(s[i+1]>s[i])
{
cnt[i+1]=max(x++,cnt[i+1]);//这里如果有更大的要取那么就应该取更大的
df2(i+1,x);
}
}
void slove( )
{
int t;
sc_int(n);
for(int i =1;i<=n;i++) sc_int(s[i]),cnt[i]=0;
s[0]=s[n+1]=2e9;//给边界赋值初始化
for(int i =1;i<=n;i++)
{
if(s[i]<s[i-1]&&s[i]<s[i+1])//如果是最小的情况
{
cnt[i]=0;//赋值
df1(i,1),df2(i,1);//从中间往两边走直到不递增(每个数最多只会走到两边所以不会超时)
}
}
// cout<<endl;
}
int main()
{
int t;
sc_int(t);
for(int k=1;k<=t;k++)
{
slove();
ll res=0;
for(int i =1;i<=n;i++)
res+=s[i]-cnt[i];
if(res%2==0)printf("Case %d: Bob\n",k);
else printf("Case %d: Alice\n",k);
}
return 0;
}