poj 2311】的更多相关文章

[题目链接] 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=2311 [算法] 博弈论——SG函数 [代码] #include <algorithm> #include <bitset> #include <cctype> #include <cerrno> #include <clocale> #include <cmath> #include <complex> #include <cstdio> #…
Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2844   Accepted: 1036 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…
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…
Cutting Game 题意: 有一张被分成 w*h 的格子的长方形纸张,两人轮流沿着格子的边界水平或垂直切割,将纸张分割成两部分.切割了n次之后就得到了n+1张纸,每次都可以选择切得的某一张纸再进行切割.最先切出只有一个格子的纸张(即有 1*1 格子的)的一方获胜.当双方都采取最优策略时,先手必胜还是必败? 题解: 这题是小白书上的,在取得游戏中必胜策略的最后一题,我照着码一遍就叫了,结果居然T了,,最后发现是cin的问题,然后关下同步就可以a了,但好险用了913ms... 还有初始化mem…
思路:求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)]=;…
题目链接 #include<iostream> #include<cstdio> #include<cstring> using namespace std; ][]; ]; int get_sg(int n,int m) { ) return sg[n][m]; ;i<=n-i;i++) vis[get_sg(i,m)^get_sg(n-i,m)]=; ;i<=m-i;i++) vis[get_sg(n,i)^get_sg(n,m-i)]=; ; ;i++…
传送门 题意:n*m的纸片,一次切成两份,谁先切出1*1谁胜 Multi-SG? 不太一样啊 本题的要求是后继游戏中任意游戏获胜就可以了.... 这时候,如果游戏者发现某一单一游戏他必败他就不会再玩了 $2*2,2*3,3*3$都不会再玩了(除非只剩下这样的纸片了),所以都可以认为是终止状态,必败 在此基础上按照Multi-SG递推就对了 #include <iostream> #include <cstdio> #include <algorithm> #includ…
Problem description: 两个人在玩如下游戏. 准备一张分成 w*h 的格子的长方形纸张,两人轮流切割纸张.要沿着格子的边界切割,水平或者垂直地将纸张切成两部分.切割了n次之后就得到了n+1张纸,每次都选择切得的某一张纸再进行切割.首先切出只有一个格子的纸张(1*1的各自组成的纸张)的一方获胜.当双方都采取最优策略时,先手是必胜,还是必败? 2<=w,h<=200 Input: w=2, h=2 Out put: LOSE 前面的硬币问题2中,有n堆硬币,我们求出每堆硬币的Gr…
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…
题意:给定一个长方形纸张,每次只能水平或者垂直切,如果切到1*1的方格就胜,问先手胜还是负. 析:根据Nim游戏可知,我们可以分别求出每个子游戏的和,就是答案,所以我们就枚举每一种切法,然后求出SG函数,那么就能得到答案. 代码如下: #pragma comment(linker, "/STACK:1024000000,1024000000") #include <cstdio> #include <string> #include <cstdlib>…
题目描述 意思就是说两个人轮流剪纸片,直到有一个人剪出1*1的方格就算这个人赢了.然后给出纸片的长和宽,求先手会赢还是会输 (1<=n,m<=200) 题解 看了一眼,这不是裸的SG吗 啪啪啪写完,一交T了,居然没算复杂度就交了... 首先明确,把纸片分成两部分之后的SG是分成两个纸片的异或. 一个非常自然的想法就是,枚举如何分割这个纸片,然后求mex. 但是这样显然会T.(200^4) 其实作为一个正常人,1*x这样的纸片是不会切出来的,这显然是一个必败局面. 然后2*2,2*3,3*2这样…
#include<stdio.h> #include<string.h> #include<set> using namespace std; ][]; int solve(int w,int h){ ){ return sg[w][h]; } set<int> my_set; ;w-i>=;i++){ my_set.insert(solve(i,h)^solve(w-i,h)); } ;h-j>=;j++){ my_set.insert(sol…
原题如下: Cutting Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 5721   Accepted: 2083 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…
题意: 有一张W*H的纸片. 每人每次可以横着撕或者竖着撕,先撕出1*1那一方胜. 数据范围: W and H (2 <= W, H <= 200) 思路: 很好抽象出游戏图的模型,用SG解决.直接看代码. 代码: int dp[maxn][maxn]; int sg(int w,int h){ if(dp[w][h]!=-1) return dp[w][h]; bool g[maxn]; mem(g,false); for(int i=2;i<=w/2;++i) g[sg(i,h)^s…
Multi-Nim 从最简单的Nim模型开始 它的定义是这样的 有\(n\)堆石子,两个人可以从任意一堆石子中拿任意多个石子(不能不拿)或把一堆数量不少于\(2\)石子分为两堆不为空的石子,没法拿的人失败.问谁会胜利 博弈分析 这个问题的本质还是Nim游戏,可以利用SG定理来解释 通过观察不难不发现,操作一与普通的Nim游戏等价 操作二实际上是将一个游戏分解为两个游戏,根据SG定理,我们可以通过异或运算把两个游戏连接到一起,作为一个后继状态 煮个栗子 SG(3)的后继状态有\(\{ (0),(1…
巴什博奕: 两个顶尖聪明的人在玩游戏,有n个石子,每人可以随便拿1−m个石子,不能拿的人为败者,问谁会胜利 结论: 设当前的石子数为\(n=k∗(m+1)\)即\(n%(m+1)==0\)时先手一定失败 HDU1846 #include<iostream> using namespace std; int main() { int C,N,M; scanf("%d",&C); while(C--) { scanf("%d%d",&N,&a…
SG函数 为了更一般化博弈问题,我们引入SG函数 SG函数有如下性质: 1.如果某个状态SG函数值为0,则它后继的每个状态SG函数值都不为0 2.如果某个状态SG函数值不为0,则它至少存在一个后继的状态SG函数值为0 如果某个局面SG函数值为0,则该局面先手必败 放到有向图中,该有向图的核就是SG值为0的点构成的集合 游戏的和 游戏的和的SG函数值=所有子游戏SG函数值的异或和Xor 如果所有子游戏都进行完毕,那么Xor=0,必败 如果某个状态的SG函数值为0,那么后手一定可以做出一种动作,保持…
A Funny Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 3861   Accepted: 2311 Description Alice and Bob decide to play a funny game. At the beginning of the game they pick n(1 <= n <= 106) coins in a circle, as Figure 1 shows. A mo…
Halloween treats Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 7644   Accepted: 2798   Special Judge Description Every year there is the same problem at Halloween: Each neighbour is only willing to give a certain total number of sweets…
Find a multiple Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7192   Accepted: 3138   Special Judge Description The input contains N natural (i.e. positive integer) numbers ( N <= 10000 ). Each of that numbers is not greater than 15000…
The Pilots Brothers' refrigerator Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22286   Accepted: 8603   Special Judge Description The game “The Pilots Brothers: following the stripy elephant” has a quest where a player needs to open a…
Flip Game Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 37427   Accepted: 16288 Description Flip game is played on a rectangular 4x4 field with two-sided pieces placed on each of its 16 squares. One side of each piece is white and the…
Corn Fields Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 9806   Accepted: 5185 Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yumm…
Sum of Consecutive Prime Numbers Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 20050   Accepted: 10989 Description Some positive integers can be represented by a sum of one or more consecutive prime numbers. How many such representatio…
Tree Recovery Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 11939   Accepted: 7493 Description Little Valentine liked playing with binary trees very much. Her favorite game was constructing randomly looking binary trees with capital le…
Seek the Name, Seek the Fame Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 17898   Accepted: 9197 Description The little cat is so famous, that many couples tramp over hill and dale to Byteland, and asked the little cat to give names t…
题目: poj 2352 Stars 数星星 题意:已知n个星星的坐标.每个星星都有一个等级,数值等于坐标系内纵坐标和横坐标皆不大于它的星星的个数.星星的坐标按照纵坐标从小到大的顺序给出,纵坐标相同时则按照横坐标从小到大输出. (0 <= x, y <= 32000) 要求输出等级0到n-1之间各等级的星星个数. 分析: 这道题不难想到n平方的算法,即从纵坐标最小的开始搜,每次找它前面横坐标的值比它小的点的个数,两个for循环搞定,但是会超时. 所以需要用一些数据结构去优化,主要是优化找 横坐…
poj   1251  Jungle Roads  (最小生成树) Link: http://poj.org/problem?id=1251 Jungle Roads Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23507   Accepted: 11012 Description The Head Elder of the tropical island of Lagrishan has a problem. A b…
Kaka's Matrix Travels Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9567   Accepted: 3888 Description On an N × N chessboard with a non-negative number in each grid, Kaka starts his matrix travels with SUM = 0. For each travel, Kaka mo…