POJ 3537 Crosses and Crosses(sg博弈)】的更多相关文章

长为n的一列格子,轮流放同种棋子,率先使棋子连成3个者胜. 可以发现每次放一个棋子后,后手都不能放在[x-2,x+2]这个区间,那么相当于每次放棋将游戏分成了两个,不能放棋者败. 暴力求SG即可 /** @Date : 2017-10-14 22:50:13 * @FileName: POJ 3537 multi-sg 暴力SG.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link : https:…
Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 3063   Accepted: 1196 Case Time Limit: 2000MS Description The game of Crosses and Crosses is played on the field of 1 × n cells. Two players make moves in turn. Each mov…
Crosses and Crosses Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 2237 Accepted: 821 Case Time Limit: 2000MS Description The game of Crosses and Crosses is played on the field of 1 × n cells. Two players make moves in turn. Each move the…
博弈论 相当于放了x的位置,左右4格都不能再放x了,谁无处可放就输. n<=2000 直接枚举后继状态,暴力求SG函数即可. 例: 0000000->x..0000 / .x..000 / ..x..00 / 0..x..0 / 00..x.. 记忆化搜索写挂了……还是顺序DP靠谱= =(跟S-Nim类似的写法,暴力求SG函数) Source Code Problem: User: sdfzyhy Memory: 692K Time: 141MS Language: G++ Result: A…
                  Crosses and Crosses Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 4049   Accepted: 1586 Case Time Limit: 2000MS Description The game of Crosses and Crosses is played on the field of 1 × n cells. Two players make moves…
题意: 给1*n的格子,轮流在上面叉叉,最先画得3个连续叉叉的赢.问先手必胜还是必败. 分析: 求状态的grundy值(也就是sg值),详细怎么求详见代码.为什么这么求要自己想的,仅仅可意会(别人都说去看game theory,呵呵). 代码: //poj 3537 //sep9 #include <iostream> #include <set> using namespace std; int grundy[2048]; int h[2048]; int get_grundy(…
Georgia and Bob Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9363   Accepted: 3055 Description Georgia and Bob decide to play a self-invented game. They draw a row of grids on paper, number the grids from left to right by 1, 2, 3, ...…
题目链接:https://vjudge.net/problem/UVA-12293 题意: 两人玩游戏,有两个盒子,开始时第一个盒子装了n个球, 第二个盒子装了一个球.每次操作都将刷量少的盒子的球倒掉,然后再从数量多的盒子中拿出若干个球放到空盒子里,最终状态为(1,1),达到这个状态的玩家获胜. 题解: 1.由于每次都是倒掉数量少的那个盒子,再对数量多的盒子进行分割,所以可以把规则简化为:初始时有n个球,每次只能拿走不多于n/2的球,最终状态为1个球,达到这个状态的玩家获胜. 2.简化游戏规则之…
题目链接:https://vjudge.net/problem/UVA-1482 题意: 有n堆石子, 每堆石子有ai(ai<=1e18).两个人轮流取石子,要求每次只能从一堆石子中抽取不多于一半的石子,最后不能取的为输家. 题解: 典型的SG博弈,由于ai的范围很大,所以不能直接求SG值,那么就打表SG值找规律,如下: 发现,当x为偶数时, SG[x] = x/2; 当x为奇数时, SG[x] = SG[x/2],即如下: 代码如下: #include <iostream> #incl…
Fibonacci again and again Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 6253    Accepted Submission(s): 2603 Problem Description 不论什么一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的: F(1)=1; F(…
题目:在1*n 的棋盘里面,A和B都在里面画叉 , 如果谁可以画了一个叉后,可以连成3个叉,那谁胜利 : 分析: 首先考虑如果我在玩游戏,我最希望对手可以画出-x-x or  -xx-   ,  这种情况 ,也就是说玩家就一定不可画成这样给对手制造机会 :  那可以当成画了一个叉后 就分成了 (x-3) , (x-2-i)  ,两个游戏 ,那我们可以根据SG的性质来解决这种分解游戏的游戏 #include<stdio.h> #include<string.h> //注意 S数组要按…
题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ]; int get_sg(int n) { ) ; ) return sg[n]; ]; //莫名其妙! //vis[]数组要声明在函数里,如果放外面会WA memset(vis,,sizeof(vis)); ;i<=n;i++) vis[get_sg(n-i-)^get_sg(i-)]=; //子局面异…
题意: 1 × n 个格子,每人每次选一个格子打上叉(不得重复),如果一个人画完叉后出现了连续的三个叉,则此人胜. 给n,判断先手胜还是先手败. 思路: 假设选择画叉的位置是i,则对方只能在前[1,i-3]中或[i+3,n]中选择画叉.子问题出现. 根据SG的定义,即可求出SG(N).看代码. 代码: int sg[2005]; int n; int dfs(int n){ if(n<0) return 0; if(sg[n]!=-1) return sg[n]; bool g[2005] =…
题目:http://poj.org/problem?id=3537 题意:给你n个格子,两个人依次在n个格子的任意空位置画"X",谁如果画了一个后,3个X连在了一起,那么那个人就获胜了.问是先手胜还是后手胜 分析: 胜利的上一个状态肯定是_XX_或者_X_X_,又因为每个人都是聪明的,也就是说如果一个人在i位置画了一个X,那么另一个人就不能在[x-2,x+2]这段区间里面画X,因为如果在这里画了个X,那么另一个人下一手就能连成三个X. 也就是说每次画个X,以它为中心的5个格子都不能再画…
[题目链接] http://poj.org/problem?id=3537 [题目大意] 在一个1*n的方格纸上下棋,谁先连三子谁就赢了,问必胜的是谁. [题解] 我们发现对于一个n规模的游戏.在i位置下棋就能将游戏拆分为i-3和n-i-2两个游戏 对于可拆分的游戏,其sg函数为拆分后游戏sg值的异或和,因此我们用记忆化搜索来记录sg值. [代码] #include <cstdio> #include <cstring> using namespace std; int n,sg[…
思路:每次画X之后都会形成2个子游戏,即i-3和n-i-2. 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<vector> #include<cstring> using namespace std; ]; int getsg(int n) { ) ; ) return sg[n]; ]={}; ;i<…
题目链接 \(Description\) 有一个一行n列的棋盘,每个人每次往上放一个棋子,将三个棋子连在一起的人赢.问是否有必胜策略. \(Solution\) 首先一个人若在\(i\)处放棋子,那么另一个人就不能在\(i-2,i-1,i+1,i+2\)处放石子,这样会使对方赢. 那么可以看做:在\(i\)处放棋子后,另一个人不能选择\(i-2,i-1,i+1,i+2\)处放石子,不能放的人输. 可以联想到Nim游戏,一个人取一个石子,另一个人可取石子\(-2\):同时是产生两个局面 即1*n的…
传送门 我也不知道为什么枚举vis必须加上一个边界才能A 以后还是都加上吧 #include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; typedef long long ll; ; inline int read(){ ,f=; ;c=getchar();} +c-';c=getchar();} return x*f;…
http://poj.org/problem?id=3710 (说实话对于Tarjan算法在搞图论的时候就没搞太懂,以后得找时间深入了解) (以下有关无向图删边游戏的资料来自论文贾志豪<组合游戏略述--浅谈SG游戏的若干拓展及变形>) 首先,对于无向图的删边游戏有如下定理性质: 1.(Fushion Principle定理)我们可对无向图做如下改动:将图中的任意一个偶环缩成一个新点,任意一个奇环缩成一个新点加一个新边:所有连到原先环上的边全部改为与新点相连:这样的改动不影响图的SG值. 2.(…
Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进行切割.最先切出只有一个格子的纸张(即有 1*1 格子的)的一方获胜.当双方都采取最优策略时,先手必胜还是必败? 题解: 这题是小白书上的,在取得游戏中必胜策略的最后一题,我照着码一遍就叫了,结果居然T了,,最后发现是cin的问题,然后关下同步就可以a了,但好险用了913ms... 还有初始化mem…
poj.org/problem?id=3537 (题目链接) 题意 给出一个1*n的棋盘,每次可以选择一个没被标记过的点打标记,若经过某一步操作使得出现3个连续的标记,则最后操作的人获胜.问是否存在先手必胜策略. Solution 我们可以很快发现,若给x位置打上标记,那么棋盘就被分成了2份,分别是x-3以及n-x-2,于是${sg[n]=mex\{sg[x-3]~XOR~sg[n-x-2]}\}$,1<=x<=n.因为n<=2000,直接暴力求解sg函数即可. 代码 // poj353…
A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4639   Accepted: 2855 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A mo…
Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6397   Accepted: 3978 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A move consists i…
题意:n堆石头,拿走最后一块的输 思路:SJ定理:先手必胜当且仅当:(1)游戏的SG函数不为0且游戏中某个单一游戏的SG函数大于1:(2)游戏的SG函数为0且游戏中没有单一游戏的SG函数大于1. 参考:[博弈]Anti,Multi,Every-SG 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #include<vector&g…
A Simple Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/65535 K (Java/Others)Total Submission(s): 1487    Accepted Submission(s): 939 Problem Description Agrael likes play a simple game with his friend Animal during the classes. I…
S-Nim Problem 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 number of heaps, all containing some, not necessarily equal, number of beads. The pl…
A multiplication game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5622   Accepted: 2811 Description Stan and Ollie play the game of multiplication by multiplying an integer p by one of the numbers 2 to 9. Stan always starts with p =…
题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][]; ]; int get_sg(int n,int m) { ) return sg[n][m]; ;i<=n-i;i++) vis[get_sg(i,m)^get_sg(n-i,m)]=; ;i<=m-i;i++) vis[get_sg(n,i)^get_sg(n,m-i)]=; ; ;i++…
题目大意:尼姆博弈,判断是否先手必胜. 题目思路: 尼姆博弈:有n堆各a[]个物品,两个人轮流从某一堆取任意多的物品,规定每次至少取一个,多者不限,最后取光者得胜. 获胜规则:ans=(a[1]^a[2] --^a[n]),若ans==0则后手必胜,否则先手必胜. #include<iostream> #include<algorithm> #include<cstring> #include<vector> #include<stdio.h>…
描述 Bessie is playing a number game against Farmer John, and she wants you to help her achieve victory. Game i starts with an integer N_i (1 <= N_i <= 1,000,000). Bessie goes first, and then the two players alternate turns. On each turn, a player can…