博弈随笔

本文详细介绍了两种经典的博弈论问题——威佐夫博弈与巴什博奕的解决方法。对于威佐夫博弈,文章给出了一个通过数学规律找到必败态的算法,并附带了C语言实现的代码;而对于巴什博奕,则提供了判断先手是否必胜的策略及代码实现。

威佐夫博弈(参考博客):

例题:https://www.nowcoder.com/acm/contest/116/G

根据规律可发现必败态(奇异局势):(0,0)、(1,2)、(3,5)、(4,7)、(6,10)、(8,13)、(9,15)、(11,18)、(12,20)....

套模板:

 1 //威佐夫博弈模板
 2 #include <stdio.h>
 3 #include <math.h>
 4 const double Gsr=(1+sqrt(5.0))/2;
 5 void swap(int &a,int &b)
 6 {
 7     int t=b;  b=a;  a=t;
 8 }
 9 int main()
10 {
11     int a,b;
12     while(~scanf("%d%d",&a,&b))
13     {
14         if(a>b)
15             swap(a,b);
16         if(a == (int)(Gsr*(b-a))) //奇异局势,先拿者输
17             puts("Lao Wang");
18         else
19             puts("Xiao Ren");
20     }
21     return 0;
22 }

巴什博奕(参考博客):两个人先后报数,最少报1最多报m个数,先报到n的获胜。

模板:

 1 #include<bits/stdc++.h>
 2 using namespace std;
 3 int main()
 4 {
 5     int n,m;
 6     while(cin>>n>>m)
 7     {
 8         if(n%(m+1)==0)
 9             cout<<"houshoubisheng"<<endl;
10         else cout<<"xianshoubisheng"<<endl;
11     }
12     return 0;
13 }

 

转载于:https://www.cnblogs.com/zxhyxiao/p/8981292.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值