牛客算法周周练9 D-石子游戏(简单博弈)

地址:https://ac.nowcoder.com/acm/contest/5902/D

解析:

对于偶数个数为偶数的时候,Alice可以在最后一步把所有偶数整合,为胜者,无论奇数个数,这点可以模拟出来:

给出两个例子:

1,奇,奇,偶数,偶数

1,奇,偶数,偶数

以上Alice均为胜者,除了1以外的偶数最后的整合,均由先手的Alice完成。

#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int maxn=1e3+10;
int s1[maxn],s0[maxn];
int main()
{
    int n;
    cin>>n;
    int o=0;
    int x;
    int jj=0;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        if(x%2==0)
            o++;
        if(x==1)
            jj++;
    }
    if(o%2==0&&(jj<n))
        cout<<"Alice"<<endl;
    else
        cout<<"Bob"<<endl;
}
原文地址:https://www.cnblogs.com/liyexin/p/13038323.html