链接:https://www.nowcoder.com/acm/contest/186/A
来源:牛客网
题目描述
Alice和Bob在玩游戏,他们面前有n堆石子,对于这些石子他们可以轮流进行一些操作,不能进行下去的人则输掉这局游戏。
可以进行两种操作:
1. 把石子数为奇数的一堆石子分为两堆正整数个石子
2. 把两堆石子数为偶数的石子合并为一堆
两人都足够聪明,会按照最优策略操作。现在Alice想知道自己先手,谁能最后赢得比赛。
输入描述:
第一行一个正整数n。(1<=n<=104) 接下来第二行n个正整数表示每堆石子的数量。每堆石子不超过105个。
输出描述:
Alice或者Bob,表示谁能最后赢得游戏。
示例1
输入
复制
3 3 2 2
输出
复制
Alice
说明
Alice只要现将两个石子数量为2的堆合并为一堆4个石子,Bob就只能把3分为两堆1和2,接下来Alice只要将2和4合并,Bob输掉了这局游戏。
题解:因为由题意可知这些操作数量是有限的所以 我们可以直接把操作数量求出来奇数Alice偶数Bob
#include<cstring>
#include<cstdio>
#include<iostream>
#include<string>
#include<queue>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<stack>
#include<functional>
using namespace std;
#define eb(x) emplace_back(x)
#define pb(x) push_back(x)
#define ps(x) push(x)
#define clr(a,b) memset(a,b,sizeof(a))
#define _INIT ios::sync_with_stdio(false);cin.tie(nullptr);cout.precision(10); cout << fixed
#define lowbit(x) x&-x
#define rep(a,b,c) for(a=b;a<c;a++)
#define inf 0x3f3f3f3f3f3f
#define MAX_N 200000+5
#define MAX_M 25
typedef long long ll;
typedef unsigned long long ull;
const ll INF=1000000000000LL;
const ll maxn=1e5+2;
typedef priority_queue<int,vector<int>,less<int> > pql;
typedef priority_queue<int,vector<int>,greater<int> >pqg;
int sta[maxn];
void init()
{
for(int i=3;i<maxn;i+=2)
sta[i]=sta[i/2+1]+1;
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("data.txt","r",stdin);
#endif
init();
int n;
while(~scanf("%d",&n))
{
int sum=0,sum2=0;
while(n--)
{
int tm;scanf("%d",&tm);
sum+=sta[tm];
sum2+=sta[tm]+(tm+1)%2;
}
sum+=sum2-1;
if(sum%2&&sum>0){printf("Alice\n");}
else {printf("Bob\n");}
}
return 0;
}