HDU 1907 John(博弈)】的更多相关文章

1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形.设糖果数为1的叫孤独堆,糖果数大于1的叫充裕堆,设状态S0:a1^a2^..an!=0&&充裕堆=0,则先手必败(奇数个为1的堆,先手必败).S1:充裕堆=1,则先手必胜(若剩下的n-1个孤独堆个数为奇数个,那么将那个充裕堆全部拿掉,否则将那个充裕堆拿得只剩一个,这样的话先手必胜).T0:a1…
题目链接: PKU:http://poj.org/problem? id=3480 HDU:http://acm.hdu.edu.cn/showproblem.php? pid=1907 Description Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to…
Problem Description Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so o…
思路: 注意与Nimm博弈的区别,谁拿完谁输! 先手必胜的条件: 1.  每一个小游戏都只剩一个石子了,且SG = 0. 2. 至少有一堆石子数大于1,且SG不等于0 证明:1. 你和对手都只有一种选择,随便怎么拿,你都赢了 2.  a:如果只有一堆石子数量大于1,那么你赢了,你可以拿完使得整个游戏的1的数量不变,剩余1个整个游戏1的数量增加. b:如果至少有两堆石子数大于1,那么你可以让SG变为0,令对手处于P态,并且当前至少有两堆数量大于1,对手无论怎么拿SG都会变成非0. 结论:当石子数量…
题目 参考了博客:http://blog.csdn.net/akof1314/article/details/4447709 //0 1 -2 //1 1 -1 //0 2 -1 //1 2 -1 //2 2 -2 //0 3 -1 //1 3 -1 //2 3 -1 //3 3 -2 //0 4 -1 //1 4 -1 //2 4 -1 //3 4 -1 //4 4 -2 //0 5 -1 //1 5 -1 //2 5 -1 //3 5 -1 /* 尼姆博弈.对于N堆的糖,一种情况下是每堆都是…
John Problem Description   Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. A…
传送门 #include<iostream> #include<cstdio> #include<cstring> using namespace std; int main() { int t; scanf("%d",&t); while(t--) { ; ,g=;//¹Âµ¥¶Ñ¡¢³äÔ£¶Ñ scanf("%d",&n); ;i<n;i++) { scanf("%d",&a…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 2034    Accepted Submission(s): 1096 Problem Description Little John is playing very funny game with his younger brother. There is one big bo…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 6000    Accepted Submission(s): 3486 Problem Description Little John is playing very funny game with his younger brother. There is one big bo…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very funny game with his younger brother. There is one big box filled wi…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 4407    Accepted Submission(s): 2520 Problem Description Little John is playing very funny game with his younger brother. There is one big bo…
很简单的博弈论问题!!(注意全是1时是特殊情况) 代码如下: #include<stdio.h> #include<iostream> using namespace std; int main(){ int i,t,n,k,m; bool flag; scanf("%d",&t); while(t--){ scanf("%d",&n); flag=;m=; ;i<n;i++){ cin>>k; m^=k;…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 4704    Accepted Submission(s): 2720 Problem Description Little John is playing very funny game with his younger brother. There is one big bo…
n个棋子,其中第k个是红色的,每个棋子只能往上爬,而且不能越过.重叠其他棋子,谁将红色棋子移到顶部谁赢. 由于只能往上爬,所以很像阶梯博弈.这题有2个限制,棋子不能重叠,有红棋存在 首先不考虑红色棋,那么我们可以视棋于棋间的距离为石子堆,这样棋子两两分组就是奇数堆,组与组间的距离就是偶数堆. 有个特殊情况k=2时,此时第一个区间石子数要减小1,不能移完,否则后手直接就能取胜了. /** @Date : 2017-10-13 23:13:24 * @FileName: HDU 4315 阶梯博弈变…
n*n棋盘,初始左上角有一个石头,每次放只能在相邻的四个位置之一,不能操作者输. 如果以初始石头编号为1作为后手,那么对于每次先手胜的情况其最后一步的四周的编号必定是奇数,且此时编号为偶数,而对于一个局面,每个人都可以操控方向以致走完整个棋盘,所以当棋盘总格数为偶数时,先手必胜,而为奇数时,后手必胜. /** @Date : 2017-10-13 21:22:47 * @FileName: HDU 1564 简单博弈.cpp * @Platform: Windows * @Author : Lw…
参见上一篇博客,里面有分析和结论. #include <cstdio> int main() { int T; scanf("%d", &T); while(T--) { , xorsum = ;//c为充裕堆的个数 scanf("%d", &n); ) c++; } ) || (xorsum && !c)) puts("Brother");//T2和S0状态必败 else puts("Joh…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submission(s): 6017    Accepted Submission(s): 3499 Problem Description Little John is playing very funny game with his younger brother. There is one big b…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1907 Problem Description Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same c…
John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s): 3745    Accepted Submission(s): 2116 Problem Description Little John is playing very funny game with his younger brother. There is one big bo…
1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结论:先手胜当且仅当(1)所有堆石子数都为1且游戏的SG值为0,(2)存在某堆石子数大于1且游戏的SG值不为0.证明:(1)若所有堆石子数都为1且SG值为0,则共有偶数堆石子,故先手胜.(2) i)只有一堆石子数大于1时,我们总可以对该堆石子操作,使操作后石子堆数为奇数且所有堆得石子数均为1 ii)有…
博弈入门题吧. 把尼姆博弈推广到n堆,都是用异或运算.还有个总结的地方是,只要先手面对的是奇异局势,则胜负都掌握在后手.本题,题目要求是最后拿完的输,尼姆博弈是最后拿完的赢.但实际上优先权都掌握在后手,前提是先手面对的是奇异局势. 本题还要注意一下每堆都是1的情况. 最后还是膜拜一下OI大神,推荐一个博客 #include<cstdio> #include<cstring> #include<cstdlib> #include<iostream> #incl…
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730 Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子 n个数异或值为0就后手赢,否则先手赢 将这题转化成Nim游戏 可以在任意一行中移动任意距离,可以向左或右,但是仔细观察发现,其实只能接近对方棋子,如果你远离对方棋子,对方可以接近你相同距离 和nim相似的是,不能不移,所以两个棋子的距离差就是SG值 #include<cstdio> #include<iostream>…
Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so on. Please note that…
n堆石子,每次选取两堆a!=b,(a+b)%2=1 && a!=b && 3|a+b,不能操作者输 选石子堆为奇数的等价于选取步数为奇数的,观察发现 1 3 4 是无法再移动的 步数为0,然后发现以6为周期,取模就好了 /** @Date : 2017-10-14 19:18:00 * @FileName: HDU 3389 基础阶梯博弈变形.cpp * @Platform: Windows * @Author : Lweleth (SoungEarlf@gmail.com…
对于任意一个 Anti-SG 游戏,如果我们规定当局面中所有的单一游戏的 SG 值为 0 时,游戏结束,则先手必胜当且仅当:  (1)游戏的 SG 函数不为 0 且游戏中某个单一游戏的 SG 函数大于 1:(2)游戏的 SG 函数为 0 且游戏中没有单一游戏的 SG 函数大于 1. John Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others)Total Submission(s):…
对于Wythoff博弈中的两个数列,An和Bn有这样的关系: An + n = Bn, An = floor(φ * n) 所以我们可以根据a b的差值来计算一个新的a出来看看这两个值是否相等. 想等的话,说明这个状态是个先手必败状态. #include <cstdio> #include <cmath> #include <algorithm> using namespace std; const double phi = (sqrt(5.0) + 1.0) / 2.…
博弈的题目,打表找规律还是相当有用的一个技巧. 这个游戏在原始的Nim游戏基础上又新加了一个操作,就是游戏者可以将一堆分成两堆. 这个SG函数值是多少并不明显,还是用记忆化搜索的方式打个表,规律就相当显然了. #include <cstdio> #include <cstring> ; ]; ]; int mex(int v) { ) return sg[v]; memset(vis, false, sizeof(vis)); ; i < v; i++) vis[mex(i)…
题意:与原来基本的尼姆博弈不同的是,可以将一堆石子分成两堆石子也算一步操作,其它的都是一样的. 分析:由于石子的堆数和每一堆石子的数量都很大,所以肯定不能用搜索去求sg函数,现在我们只能通过找规律的办法求得sg的规律. 通过打表找规律可以得到如下规律:if(x%4==0) sg[x]=x-1; if(x%4==1||x%4==2) sg[x]=x; if(x%4==3) sg[x] = x+1. 打表代码: #include<iostream> #include<cstdio> #…
题意:每次可以选择n种操作,玩m次,问谁必胜.c堆,每堆数量告诉. 题意:sg—NIM系列博弈模板题 把每堆看成一个点,求该点的sg值,异或每堆sg值. 将多维转化成一维,性质与原始NIM博弈一样. // #pragma comment(linker, "/STACK:1024000000,1024000000") #include <iostream> #include <cstdio> #include <cstring> #include &l…
思路:可以对任意一堆牌进行操作,根据Nim博弈定理--所有堆的数量异或值为0就是P态,否则为N态,那么直接对某堆牌操作能让所有牌异或值为0即可,首先求得所有牌堆的异或值,然后枚举每一堆,用已经得到的异或值再对这堆牌异或,就能得到其他牌堆的异或值,如果当前牌堆的数量大于该异或值,就说明可以拿走一些牌让当前堆牌数等于异或值,两者异或为0,则对手处于P态. AC代码 #include <cstdio> #include <cmath> #include <algorithm>…