![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
博弈论
sepNINE
it is written
展开
-
poj 2484 A Funny Game 模仿对手做对称状态
水题,直接贴代码。 //poj 2484 //sep9 #include using namespace std; int main() { int n; while(scanf("%d",&n)==1&&n) { if(n>2) printf("Bob\n"); else printf("Alice\n"); } return 0; }原创 2015-01-31 23:53:14 · 570 阅读 · 0 评论 -
poj 1704 Georgia and Bob nim博弈
题意: staircase nim。 分析; 水题,贴代码。 代码: //poj 1704 //sep9 #include #include using namespace std; int n,p[1024]; int main() { int cases; scanf("%d",&cases); while(cases--){ scanf("%d",&n); fo原创 2015-02-22 01:15:29 · 581 阅读 · 0 评论 -
poj 1740 A New Stone Game nim变形
题意: 给n堆石子,两人交替,选择一堆石头后先拿去任意颗,再把剩下的放到其他任意堆,最先拿完所有石子赢,问先手必胜还是必败。 分析; 解决此类问题的一种的思路是先构造策略,然后判断此策略能否满足1.必胜态可到必败态。2.必败态无法到必败态。 代码: //poj 1740 //sep9 #include #include using namespace std; const int m原创 2015-02-23 21:24:30 · 750 阅读 · 0 评论 -
poj 2311 Cutting Game nim与状态的grundy值
博弈论中grundy值的例题原创 2015-03-06 00:09:27 · 775 阅读 · 0 评论 -
poj 2425 A Chess Game grundy值
题意: 给一个拓扑图,在一些点上有棋子,两个玩家每次轮流将一颗棋子沿有向边移动一次,无法移动则失败。 分析: 理解nim和状态的grundy值两下就敲出来了。 代码: //poj 2425 //sep9 #include #include using namespace std; const int maxN=1024; vector g[maxN]; int vis[maxN];原创 2015-04-22 23:23:29 · 781 阅读 · 0 评论 -
poj 3480 John anti-SG博弈
题意: 跟经典的nim除了胜利条件不一样(nim当游戏者面对空的决策集判负,anti-SG当游戏者面对空的决策集判负),其他都一样。 分析: 设全局状态为s,单个游戏为t。先手必胜条件:(g(s)!=0&&Existg(t)>1)||(g(s)==0&&Anyg(t) 代码: //poj 3480 //sep9 #include using namespace std; int ma原创 2015-04-09 19:11:44 · 699 阅读 · 0 评论 -
poj 3537 Crosses and Crosses 博弈论之grundy值
题意: 给1*的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢,问先手必胜还是必败。 分析: 求状态的grundy值(也就是sg值),具体怎么求详见代码,为什么这么求要自己想的,只可意会(别人都说去看game theory,呵呵)。 代码: //poj 3537 //sep9 #include #include using namespace std; int grundy[2048原创 2015-06-24 01:03:38 · 1677 阅读 · 0 评论 -
poj 2960 S-Nim nim博弈grundy值计算法入门
题意: 给k堆石子,两人轮流向某一堆中拿,拿的个数要从给定的一个集合中取,没石子拿的输,问先手必胜还是必败。 分析: grundy值计算法的入门题。 代码: //poj 2960 //sep9 #include #include using namespace std; int s[128]; int grundy[10024]; int maxx; int num; int get原创 2015-07-01 10:13:24 · 963 阅读 · 0 评论 -
poj 2068 Nim 博弈论dp
题意: 给S个石子,2个队,每队n个人,每队轮流拿石子,每人能拿的最大石子数作为输入给出,问先拿的队必胜还是必败。 分析: 必败态的下个状态都是必胜态,必胜态的下个状态有必败态,状态明确了就能dp了,一开始定义的是dp[石子数][游戏经过步数],后来发现dp[石子数][选手编号]就可以了。 代码: //poj 2068 //sep9 #include using namespace st原创 2015-10-01 20:12:54 · 558 阅读 · 0 评论