hdu 1536/ hdu 1944 S-Nim(sg函数)】的更多相关文章

Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 1056    Accepted Submission(s): 523 Problem Description Nim is a two-player mathematic game of strategy in which players take turn…
Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10069    Accepted Submission(s): 4289 Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1)=1;F(2)=2;F(n)=F(n-1)+F(n-2)(n>=3);…
提议分析: 1 <= N <= 4747 很明显应该不会有规律的,打表发现真没有 按题意应该分成两种情况考虑,然后求其异或(SG函数性质) (1)找出单独的一个(一列中只有一个) (2)找出连续的两个都没有涂色的求SG值(打表) #include<stdio.h> #include<string.h> #define Max 4750 int dp[Max]; int mex[Max]; int flag[Max]; void Gsdp() { int i,j; int…
题目链接 题意 有一个\(n\)个珠子的环,两人轮流给环上的珠子涂色.规定每次涂色必须涂连续的\(m\)颗珠子,无法继续操作的人输.问先手能否赢. 思路 参考 转化 第一个人取完之后就变成了一条链,现只需要考虑这条链上的操作即可. SG函数计算 考虑在一个链上涂连续的\(m\)颗珠子这个问题的子问题,记当前有\(x\)颗珠子 \(x\lt m\) 显然已经无法涂了,故\(sg(x)=0\). \(x\geq m\) 设左边有\(i\)颗珠子,则右边有\((m-i)\)颗珠子.则该子问题的\(sg…
传送门 题意: 有三堆石子,双方轮流从某堆石子中去f个石子,直到不能取,问先手是否必胜,其中f为斐波那契数. 思路: 利用SG函数求解即可. /* * @Author: chenkexing * @Date: 2019-01-13 16:17:46 * @Last Modified by: chenkexing * @Last Modified time: 2019-01-15 11:10:33 */ #include <algorithm> #include <iterator>…
思路:直接打表找sg函数的值,找规律,没有什么技巧 还想了很久的,把数当二进制看,再类讨二进制中1的个数是必胜或者必败状态.... 打表: // #pragma comment(linker, "/STACK:102c000000,102c000000") #include <iostream> #include <cstdio> #include <cstring> #include <sstream> #include <str…
S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7751    Accepted Submission(s): 3266 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now.…
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.…
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # inc…
题意: 有n个盒子,每个盒子可以放一定量的石头,盒子中可能已经有了部分石头.假设石头无限,每次可以往任意一个盒子中放石头,可以加的数量不得超过该盒中已有石头数量的平方k^2,即至少放1个,至多放k^2个. 思路: 跟常规nim的区别就是加了个限制“每次加的量不超平方”.盒子容量上限是100万,那么就不能直接计算SG了,会超时.sg打表后找规律.根据剩下多少个空位来决定sg值.都是0123456这样子递增的,碰到不能一次加满就变为0,然后继续递增,一直这样. 我的方案是,对于每个盒子大小,找到除了…
题目链接 暴力出来,竟然眼花了以为sg(i) = i啊....看表要认真啊!!! #include <cstdio> #include <cstring> #include <iostream> using namespace std; #define LL __int64 ]; int sg(int x) { ],temp,i; ) return dp[x]; memset(flag,,sizeof(flag)); ;i <= x;i ++) { temp =…
题意:一个N个点的拓扑图,有M个棋子,两个人轮流操作,每次操作可以把一个点的棋子移动到它的一个后继点上(每个点可以放多个棋子),直到不能操作,问先手是否赢. 思路:DFS求每个点的SG值,没有后继的点为必败点. 注意搜索中初始化的问题. #include<stdio.h> #include<string.h> ,M=N*N; struct node{ int v,next; }e[M]; int head[N],cnt,in[N],out[N],n,sg[N],p[N]; void…
Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> using namespace std; #define maxn 10003 int step[maxn],SG[maxn],m,ans,l,a,k; bool vis[maxn]; int main(){ //freopen("input.in","r",std…
Code: #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define maxn 1003 int arr[13],step[13],SG[maxn]; bool vis[maxn]; int main(){ //freopen("input.in","r",stdin); int n,m,MAX=0,ans=0; scan…
Code: #include<cstdio> #include<algorithm> using namespace std; typedef long long ll; ll SG(ll i){ return i % 2 ==0 ? i / 2 : SG(i/2); } ll arr[100000]; int main(){ //freopen("input.in","r",stdin); int T; scanf("%d&quo…
#include <set> #include <map> #include <cmath> #include <queue> #include <vector> #include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> #include <algorithm> using namespace…
题目链接:http://acm.hdu.edu.cn/showproblem.php? pid=1944 pid=1536"> http://acm.hdu.edu.cn/showproblem.php?pid=1536 给定每一次能够取的石头数,给定非常多种情况,每一种情况有若干堆石头,推断先手胜负. SG函数打表,然后直接抑或.推断结果是否为0.第一次写SG函数,贴个代码,慢慢理解. 代码: /* ********************************************…
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之后m行,每行输入一个n表示有n个堆,每堆有n1个石子,问这一行所表示的状态是赢还是输,如果赢输入W否则L. 解题思路 如果没有每次取石子个数的限制的话,那么仅仅需要把每堆石子的个数进行异或运算即可,如果结果不是1,那么先手赢,反之后手赢. 但是这里对每次取石子的个数进行了限制,每次只能从几个数中进行…
A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick any number of candies which come from the same heap(picking no candy is not allowed)…
S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 7262    Accepted Submission(s): 3074 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now.…
S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 3077    Accepted Submission(s): 1361 Problem Description Arthur and his sister Caroll have been playing a game called Nim for some time now…
A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) Problem Description Two players take turns picking candies from n heaps,the player who picks the last one will win the game.On each turn they can pick an…
题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的博弈,对于每组数据,要先处理出SG函数, 然后使用组合游戏和来解决就ok了,对于求sg函数,很明显,就是求所有的mex,也就是未出现过的最小自然数.最后取异或就ok了. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000"…
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 623    Accepted Submission(s): 288 Problem Description Nim is a two-player mathematic game of strategy in which players take turns…
kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total Submission(s): 4972    Accepted Submission(s): 2908 Problem Description Recently kiki has nothing to do. While she is bored, an idea appears in his m…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 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就是曾经的浙江省赛题.今天,又一个关于Fibonacc…
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一个空位置处,谁不能移动了谁就输. 思路: 找规律好像找不着,那么就考虑SG函数了,因为一共只有20列,所以可以状态压缩处理,这样就可以方便的得到某个状态的后继状态. #include<iostream> #include<algorithm> #include<cstring&g…
SG函数 sg[i]为0表示i节点先手必败. 首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数.例如mex{0,1,2,4}=3.mex{2,3,5}=0.mex{}=0. 对于一个给定的有向无环图,定义关于图的每个顶点的Sprague-Grundy函数g如下:g(x)=mex{ g(y) | y是x的后继 },这里的g(x)即sg[x] 例如:取石子问题,有1堆n个的石子,每次只能取{1,3,4}个石子,先取完石子者胜利,那…
对于Nim博弈,任何奇异局势(a,b,c)都有a^b^c=0. 延伸: 任何奇异局势(a1, a2,… an)都满足 a1^a2^…^an=0 首先定义mex(minimal excludant)运算,这是施加于一个集合的运算,表示最小的不属于这个集合的非负整数. 例如mex{0,1,2,4}=3.mex{2,3,5}=0.mex{}=0. 对于一个给定的有向无环图,定义关于图的每个顶点的Sprague-Garundy函数g如下: g(x)=mex{ g(y) | y是x的后继 }. SG函数性…
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…