取石子(sg函数)

Alice和Bob有n桶石子,里面有ai个,他们每次只能其中一某堆里取奇数个,不能拿的人输,Alice总是先拿
1<=n<=200,1<=ai<=1e9
Input
第一行为 n
第二行为 n个数 ai
Output
最后获胜的人Alice或Bob
Sample Input
3
3 2 1
Sample Output
Bob

#include <iostream>
#include<algorithm>
#include <stdio.h>
#include <string>
#include <string.h>
#include <map>
#include <math.h>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <deque>
//#include <bits/stdc++.h>
using namespace std;
typedef  long long ll;
const int N=4e5+7;
const int mod=1e9+7;
inline ll read(){
    ll s=0,w=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
    while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
    return s*w;
}
int main()
{
    int x,n;
    while(cin>>n)
    {
        int ans=0;
        int m=n;
        while(n--)
        {
            cin>>x;
            if(x&1)
                ans++;
        }

        if(ans%2==0)
            cout<<"Bob"<<endl;
        else
            cout<<"Alice"<<endl;
    }
    return 0;
}

  

猜你喜欢

转载自www.cnblogs.com/zzl-dreamfly/p/11930087.html