hdu 2897(威佐夫博奕变形)

题意:容易理解。

分析:当n%(p+q)==0时,先取者必胜,必胜方案:先取q,然后对方去x个,先取者就取(p+q-x)个,最后对方就必须取玩p个,

当n%(p+q)==r(r<=p),先取者必败;当n%(p+q)==r(r>p&&r<q)先取者赢。

代码实现:


#include<stdio.h>
#include<string.h>
#include<math.h>
int main()
{
int n, p, q;
while(scanf("%d%d%d",&n,&p,&q)!=EOF)
{
if(n<=p)
printf("LOST\n");
else if(n>p&&n<=(p+q))
printf("WIN\n");
else
{
if(n%(p+q)!=0)
{
if((n%(p+q))<=p)
printf("LOST\n");
else
printf("WIN\n");
}
else
printf("WIN\n");
}
}
return 0;
}

hdu 2897(威佐夫博奕变形),布布扣,bubuko.com

时间: 2024-08-09 21:59:51

hdu 2897(威佐夫博奕变形)的相关文章

hdu 2177(威佐夫博奕)

题意:容易理解,在威佐夫博奕的基础上新增加了一条要求:就是如果在赢得条件下,输出第一步怎么走. 分析:使用暴力判断,详细见代码. 代码: #include<stdio.h> #include<string.h> #include<math.h> int a, b; int main() { double x = (1 + sqrt(5.0))/2.0; int i,k,temp,n,m; while(scanf("%d%d",&a,&

HDU 2177 威佐夫博奕 hdu1527升级版

取(2堆)石子游戏 Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1075    Accepted Submission(s): 649 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同

hdu 2897 巴什博奕变形

http://acm.hdu.edu.cn/showproblem.php?pid=2897 1.看清最后取的是输还是赢 2.分类讨论,想的时候,看怎么能回到最初状态---就是回到t*(p+q)+s的状态,以及怎么回到已经推出的必败态 #include <cstdio> #include <cstring> #include <algorithm> #include <string> #include <iostream> #include &l

HDU 1527 威佐夫博奕

取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 4285    Accepted Submission(s): 2206 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量

hdu 1527 取石子游戏(威佐夫博奕模板题)

取石子游戏 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 3562    Accepted Submission(s): 1789 Problem Description 有两堆石子,数量任意,可以不同.游戏开始由两个人轮流取石子.游戏规定,每次有两种不同的取法,一是可以在任意的一堆中取走任意多的石子:二是可以在两堆中同时取走相同数量的

hdu 2177 取(2堆)石子游戏(威佐夫博奕)

题目链接:hdu 2177 这题不是普通的 Nim 博弈,我想它应该是另一种博弈吧,于是便推 sg 函数打了个 20*20 的表来看,为了方便看一些,我用颜色作了标记,打表代码如下: 1 #include<cstdio> 2 #include<cstring> 3 #include<string> 4 #include<map> 5 #include<algorithm> 6 #include<windows.h> 7 using n

HDU 5973 Aninteresting game 威佐夫博奕(Wythoff Game)

HDU 5973:http://acm.hdu.edu.cn/showproblem.php?pid=5975 题意: 有两堆石子,每次可以从一堆石子中取任意个,或者从两堆石子中取相同个数的石子.两个人轮流用这种策略取石子,谁取完所有的石子就算胜利.问先手胜还是后手胜. 思路: 一模一样的威佐夫博奕(Wythoff Game),结论的是,假设a>b,那么如果((1+sqrt(5))* (a - b))/2 == b ,那么先手必输.但是这道题的数据比较大,所以需要java做高精度. import

hdu 2177 取(2堆)石子游戏 (威佐夫博奕)

//,在威佐夫博奕的基础上新增加了一条要求:就是如果在赢得条件下,输出第一步怎么走. # include <stdio.h> # include <algorithm> # include <iostream> # include <math.h> # include <string.h> using namespace std; int main() { int a,b,i,k; while(~scanf("%d%d",&a

博弈:巴什博奕(Bash Game)威佐夫博奕(Wythoff Game)尼姆博奕(Nimm Game)

巴什博奕(Bash Game):只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个.最后取光者得胜 对于巴什博弈可以考虑:n=(m+1)*k+s,即如果n%(m+1)!=0则先取者只需取走s物品即可保证获胜. HDU 1846:裸的. #include<iostream> #include<cstdio> #include<cstring> #include<algorithm> #include<limits.h> t