POJ 2311 Cutting Game(SG函数)】的更多相关文章

题目描述 意思就是说两个人轮流剪纸片,直到有一个人剪出1*1的方格就算这个人赢了.然后给出纸片的长和宽,求先手会赢还是会输 (1<=n,m<=200) 题解 看了一眼,这不是裸的SG吗 啪啪啪写完,一交T了,居然没算复杂度就交了... 首先明确,把纸片分成两部分之后的SG是分成两个纸片的异或. 一个非常自然的想法就是,枚举如何分割这个纸片,然后求mex. 但是这样显然会T.(200^4) 其实作为一个正常人,1*x这样的纸片是不会切出来的,这显然是一个必败局面. 然后2*2,2*3,3*2这样…
Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4798   Accepted: 1756 Description Urej loves to play various types of dull games. He usually asks other people to play with him. He says that playing those games can show his e…
[题目链接] http://poj.org/problem?id=2311 [题目大意] 给出一张n*m的纸,每次可以在一张纸上面切一刀将其分为两半 谁先切出1*1的小纸片谁就赢了, [题解] 如果切出了一张1*n的纸条,那么下一步的人一定可以切出1*1的小纸片, 所以每次切只能切出长宽大于等于2的纸片,如果有人无法做到这一点就输了, 根据这种情况我们用记忆化搜索计算sg函数来得出答案. [代码] #include <cstdio> #include <set> #include…
http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #include<cstdio> #include<cstring> #include<algorithm> #include<cmath> #include<iostream> #include<map> using namespace std; ;…
题意: 有一块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) 谁最后不能操作了,谁就输了…
思路:求SG函数!! 代码如下: #include<iostream> #include<cstdio> #include<cmath> #include<cstring> using namespace std; ][]; int getsg(int m,int n) { ) return sg[m][n]; ]; memset(vis,,sizeof(vis)); ;i<=m/;i++) vis[getsg(i,n)^getsg(m-i,n)]=;…
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…
题意:给定一个长方形纸张,每次只能水平或者垂直切,如果切到1*1的方格就胜,问先手胜还是负. 析:根据Nim游戏可知,我们可以分别求出每个子游戏的和,就是答案,所以我们就枚举每一种切法,然后求出SG函数,那么就能得到答案. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib>…
预处理出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(…
Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4806   Accepted: 1760 Description Urej loves to play various types of dull games. He usually asks other people to play with him. He says that playing those games can show his e…