POJ2315 Football Game (Nim & Bash)

33 篇文章 1 订阅
24 篇文章 0 订阅

Football Game
Time Limit: 1000MS Memory Limit: 65536K
Total Submissions: 362 Accepted: 125

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


题目链接: 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;
}




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值