POJ 2960】的更多相关文章

S-Nim Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4113   Accepted: 2158 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 h…
题意: 有一块xi*Yi的矩形巧克力,Alice只允许垂直分割巧克力,Bob只允许水平分割巧克力.具体来说,对于Alice,一块巧克力X i * Y i,只能分解成a * Y i和b * Y i其中a + b = X i和a, b > 0.对于Bob,一块巧克力X i * Y i,只能分解成X i * a和X i * b其中a + b = Y i和a ,b > 0.(每次切割只能以整数单位来切,例如一个宽为3的巧克力,你垂直切只能切成一个1,2而不能切成两个1.5) 谁最后不能操作了,谁就输了…
链接:http://poj.org/problem?id=2960 #include<stdio.h> #include<string.h> ; ; int SG[N];//SG[i]记录一堆i颗石子的SG状态 int s[M];//存储可选取的石子数目集合 int k;//s[]集合中的元素个数 int mex(int x) { )return SG[x]; }; ; i<k; ++ i ){ if( s[i] <= x ){ vi[mex(x-s[i])]=; }…
题目链接: http://poj.org/problem?id=2960 S-Nim Time Limit: 2000MS Memory Limit: 65536K 问题描述 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 con…
http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<map> using namespace std; ;…
题目链接:http://poj.org/problem?id=2960 题目大意:给定数组S,接下来给出m个游戏局面.游戏局面是一些beads堆,先给出堆数,然后是每一堆中beads的数目.游戏规则是,两个人轮流取beads,每次可以选择一堆,从中取出k个beads,k ∈S,最后不能取的人输. 分析: 取每一堆石子都可以看成是一个单独的游戏,因此,n堆石子就是n个游戏,每个子游戏的状态是其beads的数目,胜负很好判定,求出sg函数即可.最后所有游戏局面的Nim和即为此题的解. 参考代码:(注…
简单的SG函数应用!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #include<iomanip> #include<cmath> #include<cstring> #include<vector> using namespace std; ],k,a[]; int getsg(int x) { ) return sg[x]; ]&l…
S-Nim Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3694   Accepted: 1936 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 h…
预处理出SG函数,然后像普通nim一样做即可 #include<iostream> #include<cstdio> using namespace std; const int N=10005; int k,s[N],m,n,sg[N],v[N],ti,ans; int read() { int r=0,f=1; char p=getchar(); while(p>'9'||p<'0') { if(p=='-') f=-1; p=getchar(); } while(…
也算是一道模板题吧,只需按照SG函数的定义求出每个值的SG,然后异或就可以了. #include <iostream> #include <cstdio> #include <algorithm> using namespace std; ; int sg[N]; bool vis[N]; ]; ],top; int work(int w){ ,i; ;i<=k;i++){ ) p[++top]=sg[w-s[i]]; } // if(w==2) // print…