
ACM-博弈论
羁绊残阳
四川大学计算机科学与技术
展开
-
hihocoder #1163 : 博弈游戏·Nim游戏
题意:有k堆石子,每次选择一堆,在这堆中取至少一个石子,第一个无石子可取的人为输。 思路:经典游戏,直接有结论:如果这些堆的石子数为:a1,a2,a3…an.那么a1到an的异或为0,则先手有必败策略,否则先手有必胜策略。 ###代码: #include <set> #include <map> #include <cmath> #include <stack> #include <queue>原创 2015-07-20 22:38:11 · 716 阅读 · 0 评论 -
poj 2311 Cutting Game SG函数
* 分析*: 这题主要是理解SG函数。 SG函数的原理核心是定义的mex运算。这个运算的数值规则,吻合了必败态只能转移到必胜态,而必胜态必然可以找到一种方法转移到必败态的博弈规则。 这样我们就可以把一个游戏看成一个SG函数的运算了。如果一个游戏是由多个游戏组合而来的,那么根据nim游戏的证明,这多个游戏的SG值异或起来就是母游戏的SG值。 本题中母游戏可以分解为两个子游戏,异或起来就可以。原创 2016-07-21 11:14:37 · 339 阅读 · 0 评论 -
poj 1704 NIM游戏扩展
转换为nim游戏就可以了。#include <iostream>class solve { private: int T, n, A[1111]; public: void sort() { for (int i = 1; i <= n; i++) { int key = i; for (int j = i + 1;原创 2016-07-20 17:17:53 · 291 阅读 · 0 评论 -
poj 2348 Euclid's Game (博弈局面分析)
核心就是局面的分析。 - 必败态,必胜态的寻找分析 - 相互转换。 - 递推实现。#include <iostream>class solve { private: int a, b; bool ans; public: bool dfs(int a, int b) { if (a > b) std::swap(a, b); if (a原创 2016-07-20 15:45:56 · 351 阅读 · 0 评论 -
poj 2484 A Funny Game (博弈游戏,构造最优局面)
分析: 这题就是构造一个对称局面,然后发现后手只需要按照先手的方式走就可以了。#include <iostream>class solve { public: int n; public: void run(void){ while (std::cin >> n) { if (!n) return; std::cout原创 2016-07-20 15:01:32 · 282 阅读 · 0 评论 -
hdu 2147 博弈递推
简单dp或者观察一下即可找出规律,都是奇数为P态。#include <cstdio> #include <cstring> #include <iostream> #include <algorithm> #include <cmath> using namespace std; #define pr(x) cout << #x << ": " << x << " " #define pl(x)原创 2016-07-27 15:56:40 · 292 阅读 · 0 评论 -
hdu 1846 Brave Game (巴什博弈)
巴什博弈有一堆nn个,你每次可以从中取[1,m][1,m]个石子,最后取光的胜利。 递推一下可以知道n%(m+1)==0n\%(m+ 1)==0时为必败态。#include <cstring> #include <iostream> #include <algorithm> using namespace std; #define pr(x) cout << #x << ": " << x <<原创 2016-07-27 15:51:17 · 252 阅读 · 0 评论 -
hdu 1527 取石子游戏 (威佐夫博奕)
威佐夫博奕相对于nim游戏的任意堆石子,每次在任意一堆至少取一个。威佐夫博奕有两堆石子,要么在两堆同时取一样的石子,要么在其中一堆取至少一个石子。 其必败态叫做奇异局势: ⌞k1+5‾‾√2⌟,⌞k1+5‾‾√2+k⌟ | k=0,1,2...\llcorner k\frac{1+\sqrt{5}}{2}\lrcorner ,\llcorner k\frac{1+\sqrt{5}}{2}+原创 2016-07-27 15:35:12 · 333 阅读 · 0 评论 -
hdu 5754 博弈递推 dfs记忆优化
分析: 根据博弈递推的原则: -必败态只能转移到必胜态。 -必胜态一定可以转移到必败态。 令dp[i][j][op]dp[i][j][op]为在棋盘中(i,j)(i,j)位置,棋子为opop时的胜败状态,根据其子状态递推即可。 这里注意车只有对角线是必败很显然。 对于马,如果它只能走到必胜态和平态,那么它就宁愿走到平态,这比输了好。 皇后的时候转移有可能是O(n)O(n)的会复杂度过高原创 2016-07-27 14:05:38 · 359 阅读 · 0 评论 -
hdu 5724 Chess (sg函数 + 状态压缩)
分析: - 用二进制来压缩当前状态。 - 没有子状态的其sg为0(这在操作中就可自动实现。 - 对于当前状态的子状态进行枚举,二进制数一定是减小到所以符合sg函数转移。 - 求所有sg值的异或。 预处理sg函数的时间复杂度为O(220∗202)O(2^{20}*20^2)#include <iostream> #include <cstring> #include <cstdio> usi原创 2016-07-21 23:44:41 · 374 阅读 · 0 评论