Nim or not Nim? HDU - 3032】的更多相关文章

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 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…
Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provide…
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…
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 613    Accepted Submission(s): 282 Problem Description Nim is a two-player mathematic game of strategy in which players take turns…
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2513    Accepted Submission(s): 1300 Problem Description Nim is a two-player mathematic game of strategy in which players take tur…
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-size: 10.5000pt } h1 { margin-top: 5.0000pt; margin-bottom: 5.0000pt; text-align: center; font-family: 宋体; color: rgb(26,92,200); font-weight: bold; fo…
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2,1^2}=4 sg(4)=mex{0,1,2,sg(3)}=3 可以发现3和4的时候相当于互换了位置 /** @Date : 2017-10-12 21:20:21 * @FileName: HDU 3032 博弈 SG函数找规律.cpp * @Platform: Windows * @Autho…
[HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio> using namespace std; inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-'…
NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结 经典NIM游戏: 一共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子,至少取一颗,至多取出这一堆剩下的所有石子. 两个人轮流行动,取走最后一个的人胜利.Alice为先手. 我们定义: P:表示当前局面下先手必败 N:表示当前局面下先手必胜 N,P状态的转移满足如下性质: 1.合法操作集合为空的局面为P 2.可以移动到P的局面为N,这个很好理解,以为只要能转换到P局面…
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 858    Accepted Submission(s): 412 Problem Description Nim is a two-player mathematic game of strategy in which players take turns…
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 3759    Accepted Submission(s): 1937 Problem Description Nim is a two-player mathematic game of strategy in which players take tur…
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2016 Accepted Submission(s): 1048 Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing objects f…
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> # include <cstdlib> # include <iostream> # include <vector> # include <queue> # include <stack> # include <map> # inc…
博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当显然了. #include <cstdio> #include <cstring> ; ]; ]; int mex(int v) { ) return sg[v]; memset(vis, false, sizeof(vis)); ; i < v; i++) vis[mex(i)…
 这题是Lasker’s Nim. Clearly the Sprague-Grundy function for the one-pile game satisfies g(0) = 0 and g(1) = 1. The followers of 2 are 0, 1 and (1,1), with respective Sprague-Grundy values of 0, 1, and 1⊕1 = 0. Hence, g(2) = 2. The followers of 3 are 0,…
意甲冠军:经典Nim游戏转换,给你n礧pi,每个堆栈有pi石头, Alice和Bob轮流石头,意一堆中拿走随意个石子,也能够将某一堆石子分成两个小堆 (每堆石子个数必须不能为0).先拿完者获胜 思路:求SG函数后找规律. SG函数定义及求法:点击打开链接 #include<cstdio> #include<stdlib.h> #include<string.h> #include<string> #include<map> #include<…
传送门 题意: nim游戏,多了一种操作:将一堆分成两堆 Multi-SG游戏规定,在符合拓扑原则的前提下,一个单一游戏的后继可以为多个单一游戏. 仍然可以使用$SG$函数,分成多个游戏的后继$SG$值为多个游戏的异或和 然后本题规模很大,手动打一下表,发现$\mod 4=3$ 时$sg(x)=x+1$,$\mod 4=0$ 时$sg(x)=x-1$,其他不变 #include <iostream> #include <cstdio> #include <cstring>…
Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 2508    Accepted Submission(s): 1297 Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing obje…
题目链接 \(Description\) 有多堆石子, 每次可以将任意一堆拿走任意个或者将这一堆分成非空的两堆, 拿走最后一颗石子的人胜利.问谁会获得胜利. \(Solution\) Lasker's Nim游戏 具体见这 这个问题可以用SG函数来解决. 首先,操作(1)和Nim游戏没什么区别,对于一个石子数为k的点来说,后继可以为0-k-1. 而操作(2)实际上是把一个游戏分成了两个游戏,这两个游戏的和为两个子游戏的SG函数值的异或. 而求某一个点的SG函数要利用它的后继,它的后继就应该为 当…
Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.…
题目链接 暴力出来,竟然眼花了以为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堆石子,alice先取,每次可以选择拿走一堆石子中的1~x(该堆石子总数) , 也可以选择将这堆石子分成任意的两堆.alice与bob轮流取,取走最后一个石子的人胜利. 思路: 因为数的范围比较大,所以最好通过SG打表的结果找出规律在解. 打表代码 #include<cstdio> #include<cstring> ]; int find(int x) { ) return sg[x]; ]= {}; ; i<x; i++) { mex[find(i)]=;//…
题目链接 给出n堆石子, 每次可以取一堆中的任意x个(x>=1), 或者将一堆石子拆成两堆, 取到最后一堆的胜. 这个题需要打sg表找规律, 打表程序看代码. #include<bits/stdc++.h> using namespace std; #define pb(x) push_back(x) #define ll long long #define mk(x, y) make_pair(x, y) #define lson l, m, rt<<1 #define m…
题意:有N堆石子,每堆有s[i]个,Alice和Bob两人轮流取石子,可以从一堆中取任意多的石子,也可以把一堆石子分成两小堆 Alice先取,问谁能获胜 思路:首先观察这道题的数据范围  1 ≤ N ≤ 10^6, 1 ≤ [Si] ≤ 2^31 - 1,很明显数据量太大,所以只能通过打表找规律 打表后发现,如果x%4==0 sg[x]=x-1 ;如果 x%4==3 sg[x]=x+1;如果 其他情况 sg[x]=x; 代码: 打表代码: #include <iostream> #includ…
题意:给定n堆石子,两人轮流操作,每次选一堆石子,取任意石子或则将石子分成两个更小的堆(非0),取得最后一个石子的为胜. 题解:比较裸的SG定理,用sg定理打表,得到表1,2,4,3,5,6,8,7,9,10,12,11...可以发现当x%4==0时sg[x]=x-1:当x%4==3时sg[x]=x+1:其余sg[x]=x.然后异或下就出来结果了. 打表: #include <cstdio> #include <cstring> #include <iostream>…
题意:给出几堆石子数量,每次可以取走一堆中任意数量的石头,也可以将一堆分成两堆,而不取.最后取走者胜. 思路:石子数量很大,不能直接算,sg打表找出规律:正常情况下a[i]=i,但是有例外的,就是i%4=0和i%4=3的sg值是交换了的,所以要算某个状态的sg值时,若模4为0,则进行自减,若模4为3则进行自加,这样就得到了sg值.最后再求全部异或和.若0,则先手输.否则先手胜. #include <bits/stdc++.h> using namespace std; , limit=; ,,…
题意: 给你n堆石子,你每次只能操作一堆石子 1.拿去任意个,最少1个 2.把这一堆分成两堆,没有要求对半分 解析+代码: 1 //解题思路: 2 //对于一个给定的有向无环图,定义关于图的每个顶点的Sprague-Grundy函数g如下:g(x)=mex{ g(y) | y是x的后继 },这里的g(x)即sg[x] 3 //例如:取石子问题,有1堆n个的石子,每次只能取{1,3,4}个石子,先取完石子者胜利,那么各个数的SG值为多少? 4 //sg[0]=0, 5 //n=1时,可以取走{1}…
题意: n堆石头,每堆石头个数:s[1]...s[n]. 每人每次可以选择在一堆中取若干个(不能不取),或者把一堆石头分成两堆(两堆要都有石头). 无法操作者负. 数据范围: (1 ≤ N ≤ 10^6, 1 ≤ S[i] ≤ 2^31 - 1) 思路: S[i]太大了,直接求SG铁定TLE,所以先把SG打出来看看找一下规律. 分堆也挺好理解,把它抽象成游戏图去想就清晰了. 直接看代码. 代码: int sg[10005]; int s[10005]; ///打表发现当x=0,4k+1,4k+2…
学习Nim语言 nim 语法上类似python ,是一门静态编译型语言,nim 使用空格缩进标示语句块的开始和结束, 喜欢python风格的程序员应该也会很容易适应和喜欢nim的风格. nim语言官方网站 nim-lang.org #最简单的nim 程序是这样的. echo "hi nim" nim语言中文教程下载:http://files.cnblogs.com/files/gayhub/%E5%AD%A6%E4%B9%A0Nim%E8%AF%AD%E8%A8%80.rar…