SG函数博弈——poj2311】的更多相关文章

关于SG函数的博弈 首先定义必败态 x : SG[x]=0 设任意一个状态y,到所有y能到达的状态连一条边,令这些后继为z y : SG[y]=mex(SG[z]) SG[y]==0 : y就是必败态 SG[y]!=0 : y就是必胜态 所以博弈时把状态转换成有向图即可 那么n个有向图的情况 SG=SG[1]^SG[2]...^SG[n],即把所有SG异或起来即可 本题就是SG函数的应用:首先三个必败态2*2,2*3,3*2,然后将纸片切成两张等价于两个SG函数的异或 #include<iost…
SG函数: 给定一个有向无环图和一个起始顶点上的一枚棋子,两名选手交替的将这枚棋子沿有向边进行移动,无法移 动者判负.事实上,这个游戏可以认为是所有Impartial Combinatorial Games的抽象模型.也就是说,任何一个ICG都可以通过把每个局面看成一个顶点,对每个局面和它的子局面连一条有向边来抽象成这个“有向图游戏”.下 面我们就在有向无环图的顶点上定义Sprague-Garundy函数.首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最…
由于异或运算满足结合律,我们把当前状态的SG函数定义为 它所能切割成的所有纸片对的两两异或和之外的最小非负整数. #include<cstdio> #include<set> #include<cstring> using namespace std; int n,m,SG[201][201]; int sg(int x,int y) { if(SG[x][y]!=-1) return SG[x][y]; set<int>S; for(int i=2;i&l…
S-Nim Time Limit: 2000MS   Memory Limit: 65536KB   64bit IO Format: %I64d & %I64u Submit Status Description Arthur and his sister Caroll have been playing a game called Nim for some time now. Nim is played as follows: The starting position has a numb…
题目:传送门. 题意:有n行,每行最多20个棋子,对于一个棋子来说,如果他右面没有棋子,可以移动到他右面:如果有棋子,就跳过这些棋子移动到后面的空格,不能移动的人输. 题解:状态压缩博弈,对于一行2^20-1种情况来说处理出每一种情况的后继状态,求出sg值,进行异或即可. #include <iostream> #include <cstdio> #include <cmath> #include <cstring> using namespace std;…
Chess Problem Description   Alice and Bob are playing a special chess game on an n × 20 chessboard. There are several chesses on the chessboard. They can move one chess in one turn. If there are no other chesses on the right adjacent block of the mov…
Fibonacci again and again Problem Description   任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n-1)+F(n-2)(n>=3);所以,1,2,3,5,8,13……就是菲波那契数列.在HDOJ上有不少相关的题目,比如1005 Fibonacci again就是曾经的浙江省赛题.今天,又一个关于Fibonacci的题目出现了,它是一个小游戏,定义如下:1. …
Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit Status Practice HDU 3032 Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps.…
题目 洛谷传送门 题解 打表找sgsgsg规律. 严谨证明见:纳尔的博客 CODE #include <bits/stdc++.h> using namespace std; int sg(int a, int b) { if(a&1 && b&1) return 0; return sg(a+1>>1, b+1>>1) + 1; } int main () { int T, n; scanf("%d", &T…
Stone Game II comes. It needs two players to play this game. There are some piles of stones on the desk at the beginning. Two players move the stones in turn. At each step of the game the player should do the following operations.   First, choose a p…