poj 2315 Football Game (博弈 nim k game)
来源:互联网 发布:mac装windows虚拟机 编辑:程序博客网 时间:2024/05/23 11:58
题目链接
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
将这些距离稍微转化一下,就可以看成一个经典的nim游戏,唯一不同的地方就是由只能从一堆中取变成了要从m个堆里取,这种游戏也有一种名称为nimk游戏。
典型的nim游戏是将各石子堆的数量进行异或,结果为0时为必败态,而异或又称为半加运算,只执行加法而不进位,原始的nim游戏为1堆,所以XOR时以二为进位,而现在要执行的堆数为m,即以m+1为进位,我们可以先按照普通加法,将二进制下每个位上的数字加起来,最后将他们分别mod(m+1)即可。
#include<cstdio>#include<cstdlib>#include<cstring>#include <cmath>#include<iostream>#include<algorithm>#define maxn 35#define PI 3.14159265358979323846264338327950288using namespace std;int m,n,l,r;int s[maxn];int XOR[100];int getdis(int k){ return floor(k/(2*PI*r))+1;}int main(){ while(cin>>n>>m>>l>>r) { int k =getdis(l); //每次踢得距离都为周长的整数倍,每次最多能取的石子个数为k-1 for(int i=0;i<n;i++) { int p; cin>>p; s[i]=getdis(p)%k; //nim游戏每个石子堆的个数 } memset(XOR,0,sizeof(XOR)); int maxi=-1; for(int i=0;i<n;i++) { int g=s[i],p=0; for(int j=0;g;g>>=1,j++) { XOR[j]+=g&1; p++; maxi=max(maxi,p); } } bool flag =false; for(int i=0;i<maxi;i++) if(XOR[i]%(m+1)) flag=true; if(flag) cout<<"Alice"<<endl; else cout<<"Bob"<<endl; } return 0;}
- poj 2315 Football Game (博弈 nim k game)
- NIMK博弈游戏,POJ-2315 Football Game
- poj 2315 Football Game nimk 博弈
- HDU5011 Game(Nim博弈)
- Matrix Game (Nim博弈)
- HDU5011 Game(Nim博弈)
- Northcott Game (Nim博弈)
- POJ 2234 Matches Game (nim博弈裸题)
- POJ Cutting Game(Nim博弈+grundy数)
- POJ 2234 Matches Game (经典Nim博弈)
- Northcott Game + nim博弈
- hdu3389 Game NIM博弈
- hdu1730Northcott Game NIM博弈
- leetcode---Nim Game---博弈
- Nim Game 博弈游戏
- Northcott Game + 博弈 + nim博弈
- HDU 5011 Game(Nim博弈)
- 2.Nim Game(尼姆博弈)
- 5-31 字符串循环左移
- hdu 3790
- Git/GitHub 是什么样的存在
- 剑指Offer—— 最小的K个数
- 最小代价;;;;
- poj 2315 Football Game (博弈 nim k game)
- 阿里前端Web编程测试题——Javascript自定义一个对话框
- Optimal Milking poj2112 二分+最大流
- 连连看和冰壶游戏
- java安全架构____多种数字证书简介(X509,cer,pem,pfx,keystore)
- 为什么在调用delete[]时,括号中不需要指明元素的个数?
- 我们的老照片 CSDN郑州俱乐部活动纪念
- 深入理解 new 的运行机制
- 运算符重载-编程题#1(C++程序设计第4周)