HDU 3404 Switch lights(Nim积)题解】的更多相关文章

题意:在一个二维平面中,有n个灯亮着并告诉你坐标,每回合需要找到一个矩形,这个矩形xy坐标最大的那个角落的点必须是亮着的灯,然后我们把四个角落的灯状态反转,不能操作为败 思路:二维Nim积,看不懂啊,只能套模板了 参考:HDU 3404 Switch lights (NIM 积) 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #inc…
(Nim积相关资料来自论文曹钦翔<从"k倍动态减法游戏"出发探究一类组合游戏问题>) 关于Nim积计算的两个函数流程: 代码实现如下: ][]={,,,}; int Nim_Multi_Power(int x,int y) { ) return m[x][y]; ; for(;;a++) <<(<<a))&&x<(<<(<<(a+)))) break; <<(<<a); int p…
http://acm.hdu.edu.cn/showproblem.php?pid=3404 题目 http://www.doc88.com/p-5098170314707.html 论文 nim积在22页附近 http://blog.csdn.net/kele52he/article/details/77099890 抄的代码的来源 根据论文相关部分和自己的理解的介绍.(nim积其实没什么卵用,学这种毒瘤的都有猫病.) nim和其实就是异或,想一下之前sg函数或者nim游戏结算的时候,是几堆在…
主要是求NIM积!!! 代码如下: #include<iostream> #include<cstdio> #include<stack> #include<cstring> #define ll __int64 using namespace std; ][]; int nim(int x,int y); int _nim(int x,int y){ <<x+y; int &F=f[x][y]; )return F; ,e=; ;i&l…
思路:三维Nim积 代码: #include<set> #include<map> #include<stack> #include<cmath> #include<queue> #include<vector> #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> typedef long l…
由于某毒瘤出题人 redbag 不得不学习一下这个史诗毒瘤算法. 本文参考了 Owaski 的 GameTheory 的课件. 定义 我们对于一些二维 \(\mathrm{Nim}\) 游戏(好像更高维也行),可以拆分成两维单独的 \(\mathrm{Nim}\) 然后求 \(\mathrm{Nim}\) 积. 定义为 \[ x \otimes y = \mathrm{mex}\{(a \otimes b) \oplus (a \otimes y) \oplus (x \otimes b), 0…
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…
http://poj.org/problem?id=3533 变成三维的nim积..前面hdu那个算二维nim积的题的函数都不用改,多nim积一次就过了...longlong似乎不必要但是还是加上了 代码 #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<map> #include<…
题目描述 题解: 首先,由$SG$定理得SG(x,y)=mex(SG(x',y)^SG(x,y')^SG(x',y'))(x'<x,y'<y) 这里的$SG(x,y)$叫$Nim$积. $Nim$积满足交换律.结合律以及对$Nim$和(异或)的分配律. 代码: #include<cstdio> #include<cstring> int T,n; ][]; int nim_mul(int x,int y) { if(x<y)x^=y^=x^=y; &&am…
Nim积总不能一直打四次暴力吧! 用SG定理等东西,可以证明 \((N, \oplus, \otimes)\) 构成一个域.(证明很难,我不会) 其中 \(\oplus\) 为异或, \(x \otimes y = \mathop{\textrm{mex}}_{1 \leq i < x, 1 \leq j < y} \left\{ (i \otimes y) \oplus (x \otimes j) \oplus (i \otimes j)\right\}\),即暴力对子状态计算. 然后还有优…
A Simple Nim 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5795 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…
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)…
A Simple Nim Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 79    Accepted Submission(s): 48 Problem Description Two players take turns picking candies from n heaps,the player who picks the las…
Problem Description Nim is a mathematical game of strategy in which two 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…
http://acm.hdu.edu.cn/showproblem.php?pid=4994 Nim游戏变成从前往后有序的,谁是winner? 如果当前堆数目为1,玩家没有选择,只能取走.遇到到不为1的堆,则当前回合行动者可以选择下次选择的先后手.考虑之后的状态为S,如果S为必败态,则玩家可以取完当前堆,下轮变后手,否则,将当前堆数目变为1,下轮先手. #include <cstdio> #include <cstdlib> #include <cmath> #incl…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3177 \(describe\): 有一个山洞,山洞的容积最大为\(v\).现在你有\(n\)个物品,这些物品在往山洞里搬和放在山洞所需要占用山洞的体积是两个不同的值\(B\),\(A\).你可以理解为在搬运这个物品进洞时需要的容积为一个\(B\),放下物品后的容积是一个\(A\).在任何时刻搬运物品都不允许超过山洞的最大容积.试求能不能把所有物品搬进去 题解: 这个题正解是贪心...没错... 题目…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3915 题目大意是给了n个堆,然后去掉一些堆,使得先手变成必败局势. 首先这是个Nim博弈,必败局势是所有xor和为0. 那么自然变成了n个数里面取出一些数,使得xor和为0,求取法数. 首先由xor高斯消元得到一组向量基,但是这些向量基是无法表示0的. 所以要表示0,必须有若干0来表示,所以n-row就是消元结束后0的个数,那么2^(n-row)就是能组成0的种数. 对n==row特判一下. 代码:…
Switch Game Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 10200    Accepted Submission(s): 6175 Problem Description There are many lamps in a line. All of them are off at first. A series of op…
以防万一,题目原文和链接均附在文末.那么先是题目分析: [一句话题意] “就是统计一篇文章里不同单词的总数”(已经是一句话了..) [题目分析] 明显需要去重,上set,因为按行分析,又没有EOLN用,于是上istringstream. [算法流程] 读一行塞一行干一行爱一行.....发这篇的目的其实是备忘istringstream的用法的.这道题没难点. #include <iostream> #include <sstream> #include <string>…
SG打表找规律 HDU 5795 题目连接 #include<iostream> #include<cstdio> #include<cmath> #include<algorithm> #include<cstring> using namespace std; #define MAXN 10000 int sg[MAXN],visit[MAXN]; int getsg(int n) { int i,j; ) return sg[n]; mem…
http://acm.hdu.edu.cn/showproblem.php?pid=2053 Problem Description There are many lamps in a line. All of them are off at first. A series of operations are carried out on these lamps. On the i-th operation, the lamps whose numbers are the multiple of…
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…
如果我们规定当局面中所有的单一游戏的SG值为0时,游戏结束,则先手必胜当且仅当:(1)游戏的SG!=0 && 存在单一游戏的SG>1:(2)游戏的SG==0  && 任意单一游戏的SG==0. /** @Date : 2017-10-15 01:49:12 * @FileName: HDU 2509 基础anti-sg.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com) * @Link…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2053 题目大意:灯开始是关着的,有n盏灯,i从1数到n每当灯的序号是i的倍数的时候就对灯进行一次操作(开->关,关->开),求最后第n盏灯是关着还是开着. 解题思路:直接对第n盏灯模拟也可以,但是有规律更好不是吗~.其实就是判断n的约束奇偶性,奇数就开着,偶数就关着. 当一个数不是完全平方数:如18约数为:(3,6),(2,19),(1,15)约数个数总会是偶数,因为每个约数都有一个对应的不同的约…
假如把Nim游戏的取胜规则改为谁取走最后一个石子谁输的话 先手必胜当且仅当: 1.所有堆的石子数都为1且游戏的SG值为0 2.有些堆的石子数大于1且游戏的SG值不为0…
题意:在nim游戏的规则上再增加了一条,即可以将任意一堆分为三堆都不为0的子堆也视为一次操作. 分析:打表找sg值的规律即可. 感想:又学会了一种新的方法,以后看到sg值找不出规律的,就打表即可~ 打表代码如下: #include <stdio.h> #include <algorithm> #include <string.h> #include <set> using namespace std; +]; int main() { sg[] = ; ;i…
HDU 1069 Monkey and Banana 纵有疾风起 题目大意 一堆科学家研究猩猩的智商,给他M种长方体,每种N个.然后,将一个香蕉挂在屋顶,让猩猩通过 叠长方体来够到香蕉. 现在给你M种长方体,计算,最高能堆多高.要求位于上面的长方体的长要大于(注意不是大于等于)下面长方体的长,上面长方体的宽大于下面长方体的宽. 输入输出 开始一个数n,表示有多少种木块,木块的数量无限,然后接下来的n行,每行3个数,是木块的长宽高三个参量 输出使用这些在满足条件的情况下能够摆放的最大高度 解题思路…
Consider a positive integer X,and let S be the sum of all positive integer divisors of 2004^X. Your job is to determine S modulo 29 (the rest of the division of S by 29). Take X = 1 for an example. The positive integer divisors of 2004^1 are 1, 2, 3,…
一个组合游戏题. 解答: 从后面往前面推,首先n-1是必胜位,然后前面的k位是必败位,如此循环下去.所以题目就容易了! 代码: #include<cstdio> using namespace std; int main() { int n,k; while(scanf("%d%d",&n,&k)&&(n+k)) { ); )puts("Tang"); else puts("Jiang"); } ; }…
本题乍看像是线段树之类的区间操作,只是由于仅仅是须要查找ip的前缀,故此事实上是使用Trie来做. 挺高难度的Trie应用,做完这道题之后说明Trie功力有一定火候了. 这里的Trie使用到了Delete函数.这是个Trie函数中最难的函数了,当然要使用数组记录的方法水掉.也是能够的.这里不水.给出delete函数. 考点难点: 1 Trie的操作函数的灵活运用.主要难点是delete函数的灵活运用 2  在叶子节点全部的group id, 删除的时候要注意,不能一气删除了,有多个group i…