Game Theory: 公平博弈
Notes: The following excerpt is from a book 《GAME THEORY》by Thomas && S.Ferguson and a paper by Ulyssess.
一. 公平聯合博弈
公平聯合博弈(Impartial combinatorial game ):兩個參與者,輪流活動;狀態集合有限;對每個局面(position),每個參與者有相同的地位; 在“通常規則”下,最後一個活動的參與者贏;滿足“結束條件”,即博弈在有限次“活動”之後必然會結束。由此可以看出沒有平手(draw)的出現!
P局面(P-positions )和N局面(N-positions)是被遞歸地定義的:1)所有的最終局面為P局面;2)從每一個N局面出發,存在至少一次可選“活動”到達P局面;3)從每一個P局面出發,每一次“活動”都指向N局面。P局面是必敗局面,而N局面是必勝局面。
由歸納法可知:每一個局面要么是P局面,要么是N局面。
圖博弈(Graph Game)是和DAG(directed acyclic graph)聯繫在一起的。表示為G=(X,F) ,其中X為狀態集合,而F為X上的一個函子,F(x)表示狀態x時所有可能的可選活動能到達的狀態,簡稱x的可選狀態集合(the followers of x)。如果F(x)為空集,則表示x為最終局面。
圖博弈的和(The Sum of n Graph Games):用Gi=(Xi, Fi)表示n個公平組合博弈,i=1~n;記G =(X,F)為n個博弈的和,其中G = G1+···+Gn ,X = X1×···×Xn,F(x)= F(x1,...,xn)= F1(x1) ×{x2}×···×{xn} U ··· ∪{x1}×{x2}×···× Fn(xn).
通過畫圖,可以知道每個公平聯合博弈可以表示為一個圖博弈!
二.SG函數(Sprague-Grundy function)
首先定義集函數mex (Minimal EXclusive):對於由若干自然數組成的集合S,mex(S)表示不在S的最小非負自然數 。
接著定義SG函數SG : V → N 為SG(u) = mex{SG(w) : w ∈ F(u)} = min{n ≥ 0: n != SG(w) for w ∈ F(u)}.
用SG函數可以有效地判斷一個局面是P的還是N的:對一個局面u,1)如果SG(u)=0,則u是P局面;2)如果SG(u)!=0,則u是一個N局面。(用歸納法證明)
SG定理:G =(X,F)為n個公平組合博弈G1,...,Gn 的和,每個Gk (k = 1, 2, . . . , n) 為有限DAG. 則對於每個u = (u1, . . . , un) ∈ G,有
SG(u) = SG(u1) ⊕ . . . ⊕ SG(un).
proof: We divide the proof into two parts
1) For any given nonnegative integer a < b, there is w ∈ F(u) such that SG(w)=a;
2) The set {w |∈ F(u), SG(w)=b} is empty.
the proof of 1): Let d=a⊕b and assume that k(d) is the kth digit in the binary expansion of d, so that 2^(k-1)≤d<2^k. Since a<b, we have k(a)=0 and k(b)=1. Thus, there is at least one is 1 in {k(SG(u1)),...,k(SG(un))}, and WLOG we assume k(SG(u1))=1. Then d ⊕SG(u1)< SG(u1), and by the definition of SG, there exists w1∈ F1(u1) such that SG(w1)=d⊕SG(u1). The following computation completes the proof:
SG(w1,u2,u3,…,un)=SG(w1)⊕SG(u2)⊕…⊕SG(un)= d⊕SG(u1)⊕SG(u2)⊕…⊕SG(un) = d⊕b= a⊕b⊕b= a
the proof of 2): By contradiction. If there exist w={w1,u2,…,un}(w1 ∈ F1(u1) )∈ {w |∈ F(u), SG(w)=b} , we could get the equation SG(u1)⊕SG(u2)⊕…⊕SG(un) = SG(w1)⊕SG(u2)⊕…⊕SG(un). By the cancellation law, SG(u1)= SG(w1).
三.計算SG函數的算法
sg[v]:=-1 , for all v \in V;
N:=|V|; sg[sink]=0;
int cal_sg(int x)
{
if(sg[x] != -1) return sg[x];
bool v[N] = {0};
for(i \in Adj[x])
v[cal_sg(i)] = 1;
sg[x] = 0;
while(v[sg[x]]) sg[x]++; //compute the mex
return sg[x];
}
#include <iostream> //M:240k T:16ms
using namespace std;
int main()
{
int M;
long a[21];
while(cin>>M){
int sg=0;
for(int i=1;i<=M;i++){
cin>>a[i];
sg=sg^a[i];
}
sg==0?puts("No"):puts("Yes");
}
return 0;
}
#include <iostream> //M:2280K T:250MS
#include<algorithm>
using namespace std;
int k,m,l;
int si[101],hi[101];
int sg[10001];
int cal_sg(int x)
{
if(sg[x]!=-1) return sg[x];
bool v[1001]; //要在函數內定義并初始化
memset(v,0,sizeof(v));
for(int i=0;i<k;i++){
int temp=x-si[i];
if(temp < 0) break;
v[cal_sg(temp)]=1;
}
sg[x]=0;
while(v[sg[x]]) sg[x]++;
return sg[x];
}
int main()
{
while(cin>>k && k){
for(int i=0;i<k;i++){
cin>>si[i];
}
sort(si,si+k);
memset(sg,-1,sizeof(sg));
cin>>m;
for(int i=0;i<m;i++){
cin>>l;
int temp=0;
for(int j=0;j<l;j++){
cin>>hi[j];
temp=temp^cal_sg(hi[j]);
}
if(temp==0)
cout<<"L";
else
cout<<"W";
}
cout<<endl;
}
return 0;
}
//從2001.11.4這一天向前推理,猜想跟奇偶性有關,假設每個月是31天的話,有結論:“如果‘月+日=偶數’則必勝,否則必敗。”
//再考慮那些30天的月份,只有09.30和11.30這兩天特殊,都是必勝。
//最後就是leap years了,經研究也是一樣的結論。
#include <iostream> //232K 0MS
using namespace std;
int main()
{
int n,month,data;
cin>>n;
for(int i=1;i<=n;i++){
cin>>month>>month>>data;
bool Yes=1;
if((month+data)%2) Yes=0;
if((month==9 && data==30)||(month==11 && data==30)) Yes=1;
Yes?puts("YES"):puts("NO");
}
return 0;
}
#include <iostream> //M:5148k T:1688ms
using namespace std;
int g[1001][1001];
int N,M;
int sg[1001];
int cal_sg(int x,int n)
{
if(sg[x]!=-1) return sg[x];
bool v[1001];
memset(v,0,sizeof(v));
for(int i=0;i<n;i++)
if(g[x][i])
v[cal_sg(i,n)]=1;
sg[x]=0;
while(v[sg[x]]) sg[x]++;
return sg[x];
}
int main()
{
while(cin>>N){
memset(g,0,sizeof(g));
memset(sg,-1,sizeof(sg));
for(int i=0;i<N;i++){
int tempM;cin>>tempM;
if(tempM==0){
sg[i]=0;continue;
}
for(int j=0;j<tempM;j++){
int tem;cin>>tem;
g[i][tem]=1;
}
}
while(cin>>M && M){
int k=0,position;
for(int i=0;i<M;i++){
cin>>position;
k=k^cal_sg(position,N);
}
k?puts("WIN"):puts("LOSE");
}
}
return 0;
}
4.5 poj1704“Georgia and bob”
#include <iostream> //244K 0MS
#include <algorithm>
using namespace std;
int T,N;
int a[1001];
int main()
{
cin>>T;
for(int i=1;i<=T;i++){
cin>>N;
a[0]=0;
for(int j=1;j<=N;j++) cin>>a[j];
sort(a,a+N+1); //Attension: sort a[0],...,a[N] increasingly
for(int j=N;j>0;j--) a[j]=a[j]-a[j-1]-1;
int ans=0;
for(int j=N;j>0;j=j-2) ans^=a[j];
ans?puts("Georgia will win"):puts("Bob will win");
}
return 0;
}
4.6 poj2348“Euclid game”
//For the given example(25,7),25/7=3>1,thus,whether the position (4,7) is N-position or not,Stan can control which one to reach (4,7).
#include <iostream> //240K 0MS
using namespace std;
int main()
{
int a,b;
while(cin>>a>>b){
if(a==0 && b==0) break;
if(a==b){cout<<"Stan wins"<<endl;continue;} //border
if(a<b){int temp=a;a=b;b=temp;}
bool Stan=1;
while(1){ //recursion
if(a/b>1){Stan?puts("Stan wins"):puts("Ollie wins");break;}
int temp=a%b;a=b;b=temp;
if(b==0){Stan?puts("Stan wins"):puts("Ollie wins");break;}
Stan=!Stan;
}
}
return 0;
}
4.7 to be continued
Game Theory: 公平博弈相关推荐
- 【学习笔记】平等博弈及常见的公平博弈类型
文章目录 平等博弈 nim堆 SG定理 nim和 常见的公平博弈模型 bash博弈 nim博弈 nim-k博弈 wythoff博弈 扩展wythoff博弈 fibonacci博弈 阶梯博弈 green ...
- 树上删边游戏及其拓展(公平博弈:克朗原理+费森原理)
参考资料 问题描述 在某一棵树上删除一条边,同时删去所有在删除后不再与根相连的部分 双方轮流操作,无法再进行删除者判定为失败 一个游戏中有多棵树,我们把ta们的根都放在地板上,方便之后的处理 在此,我 ...
- HDU 4023 (博弈 贪心 模拟) Game
如果硬要说这算是博弈题目的话,那这个博弈是不公平博弈(partizan games),因为双方面对同一个局面做出来的决策是不一样的. 我们平时做的博弈都是公平博弈(impartial games),所 ...
- 寻找必败态——一类博弈问题的快速解法
博弈是信息学和数学试题中常会出现的一种类型,算法灵活多变是其最大特点,而其中有一类试题更是完全无法用常见的博弈树来进行解答. 寻找必败态即为针对此类试题给出一种解题思路. ...
- 博弈论学习之巴什博弈,尼姆博弈, sg博弈
博弈论真是一个神奇的东西,感觉和博弈论厉害的人玩游戏绝对会输. 这个博客讲的很好很全面 此类问题一般有如下特点: 1.博弈模型为两人轮流决策的非合作博弈.即两人轮流进行决策,并且两人都使用最优策略来获 ...
- 博弈论总结 必胜点 SG函数 巴什博弈 尼姆博弈
摘要 主要算法思想,应用领域,近年来的出题情况 博弈是信息学和数学试题中常会出现的一种类型,算法灵活多变是其最大特点,而其中有一类试题更是完全无法用常见的博弈树来进行解答. 寻找必败态即为针对此类试题 ...
- 转载:概率与梳理统计||数学基础
导言:本文从微积分相关概念,梳理到概率论与数理统计中的相关知识,但本文之压轴戏在本文第4节(彻底颠覆以前读书时大学课本灌输给你的观念,一探正态分布之神秘芳踪,知晓其前后发明历史由来),相信,每一个学过 ...
- Probability, Matringale,Markov Chain, MCMC
一.基本知识 1. 条件概率 条件概率是指在某件事情已经发生的前提下,另一件事情在此基础上发生的概率,举例来说P(A丨B)表示B发生的基础上,A也发生的概率,基本公式为: 2. 条件期望 在上述概率下 ...
- martingale、markov chain、Monte Carlo、MCMC
文章结构如下: 1: MCMC 1.1 MCMC是什么 1.2 为什么需要MCMC 2: 蒙特卡罗 2.1 引入 2.2 均匀分布,Box-Muller 变换 2.3 拒绝接受采样(Acceptanc ...
最新文章
- 参考地、保护地、大地的概念
- java协变 生产者理解_Java进阶知识点:协变与逆变
- cenotos 卸载mysql_CentOS 6.2编译安装Nginx1.0.12+MySQL5.5.21+PHP5.3.10 | 系统运维
- vsftpd的不同安装方式及服务控制脚本
- python基础语法-三大内建数据结构之字典(dict)
- androidstudio新建项目中在布局文件中不显示title的方法
- Hadoop1.1.2开发笔记(一)
- iostate知识要点
- 怎样把win7系统下的屏幕设置成护眼的非常柔和的豆沙绿色?
- 多功能通用报修管理平台后勤维修软件
- 微型计算机控制系统的硬件组成
- 电子邮箱地址格式怎么写?企业电子邮箱格式教程
- 是指可以显示网页服务器或者文件,浏览器是指可以显示网页服务器或者文件系统的HTML文件(标准通用标记语言的一个应用)内容,并让用户与这些文件交互的一种软件。...
- Nmap使用技巧总结
- 怎样装系统(附图文教程)
- 小飞鱼通达二开 致远OA启动时报错“无法初始化数据库连接池,系统无法启动”的问题处理(图文)
- html 链接到 appstore,如何在微信浏览器内打开App Store链接
- uafxcwd.lib(dllmodul.obj) : error LNK2005: _DllMain@12 already defined in main.obj
- 吴恩达 深度学习系列--卷积神经网络(Convolutional Neural Networks)-03(目标检测)
- Python 切片