sg函数:sg函数是博弈中的确定一个position性质的一个函数,全称是sprague-grundy。
性质1:对于所有的p-position,都有sg = 0;对于所有的n-position都有sg != 0;
性质2:某点a的sg函数的值由它的后继的sg函数的值来决定,设后继为b, c, d, e……则sg(a) = mex(sg(a), sg(b), sg(c), sg(d), sg(e),……)
mex是不属于这个集合的最小非负整数。
应用范围:在此无环图中谁无法再次移动,便是输。(如果谁无法移动,便是赢,暂时不知如何解决。)
应用:通过判断该点,sg = 0是p点,sg != 0是N点。
构造sg函数的方法:
方法一:打表
例题:hdu-1536-S-nim 点击打开链接
/*
收获:
*/
#include<iostream>
#include<cstdlib>
#include<vector>
#include<map>
#include<cstring>
#include<set>
#include<string>
#include<algorithm>
#include<sstream>
#include<ctype.h>
#include<fstream>