Football Game
Description
Alice and Bob both love football very much, and both of them are vanguards. They are both good at football control. One day after a football match, they play an interesting game, in which they shoot footballs forward the goal directly. There are N footballs in front of the goal, and they play this game in turn. For example, if it is Alice's turn, Alice can choice some footballs (the number of footballs mush equal or less than M) and shoot them forward. Because the footballs' quality is not very good, footballs are not a complete sphere and can only roll integer times of its girth. And because of restriction of the friction and strength of them, they cannot shoot a football farther then L centimeters. Of course, they know the radius of a football is R centimeters. Alice and Bob love this game very much. If both of them have unlimited IQ and precision shooting skill, can you guess who can win the football game? By the way, though Alice is as strong as Bob, Alice is a girl, so she will shoot first.
Input
The input consists of several cases, each of which contains two lines.
For each test case, the first line contains 4 integers N, M, L and R (1 <= M <= N <= 30, 0 < L < 100000000, 0 < R < 10000), separated by a single space. N is the number of the footballs, M is the maximum number of footballs one player can shot in one turn, L is the maximum distance that a player can shoot, and R is the radius of footballs. The next line contains N numbers, S(1), S(2), ..., S(N) (0 < S(i) < 100000000), which describe the distance between footballs and the goal. Output
For each case output contains one line describing the name of the winner.
Sample Input 2 1 30 1 8 14 2 1 30 1 8 12 2 1 30 1 8 10 2 1 30 1 40 200 Sample Output Alice Bob Bob Bob Source
POJ Monthly,uni
|
题目链接: http://poj.org/problem?id=2315
【题意】Alice和Bob轮流玩一个足球游戏,有n个足球,每个人每回合最多踢m个足球,每次踢球的距离不能超过L且距离为球的周长的整数倍,球的周长为R,无法操作这为输。
【思路】首先,对L进行转化,k = L/(2*PI*R),类比拿石子游戏,k就是每次从一堆石子中能够拿的最多的个数,所有对a[i[也应该进行类似的转化。就一堆石子而言,发现符合bash博弈的游戏规则,所以可以对单堆石子进行取模,即a[i] %= (k+1);对于多堆石子而言,类比Nim博弈,发现不同之处在于nim博弈每次只允许对一堆石子进行操作,而该游戏则允许至多对m堆游戏进行操作,nim游戏采用二进制思想,类比可得,该游戏可以采用m+1进制思想,规则同nim博弈。
【代码如下】
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const double PI = acos(-1.0);
int n,m,l,r,a[110],sg[110];
int dist(int x){
return (x / (2*PI*r) + 1);
}
int solve(){
int k = dist(l);
memset(sg,0,sizeof(sg));
for(int i = 1; i <= n; i ++){
int x = dist(a[i]);
x %= k;
for(int j = 1; x; j ++, x /= 2){
sg[j] += x&1;
}
}
for(int i = 1; i <= 27; i ++){
if(sg[i] % (m+1)){
return 1;
}
}
return 0;
}
int main(){
while(~scanf("%d%d%d%d",&n,&m,&l,&r)){
for(int i = 1; i <= n; i ++) scanf("%d",&a[i]);
printf("%s\n",solve()? "Alice" : "Bob");
}
return 0;
}