poj 2960 S-Nim (SG)】的更多相关文章

题意: 有一张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…
[HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio> using namespace std; inline int read() { int x=0;bool t=false;char ch=getchar(); while((ch<'0'||ch>'9')&&ch!='-')ch=getchar(); if(ch=='-'…
POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears that an extraordinary meteor shower is coming; reports say that these meteors will crash into earth and destroy anything they hit. Anxious for her sa…
NIM(3)两堆石头的游戏 1. 问题描述 假设有两堆石头,有两个玩家会根据如下的规则轮流取石头:每人每次可以从两堆石头中各取出数量相等的石头,或者仅从一堆石头中取出任意数量的石头:最后把剩下的石头一次拿光的人获胜.请问在哪些局面(依据两堆石头中的石头个数)下,先取石头的玩家有必胜的策略. 2. 解法 类似构造质数的筛选方法,这里我们利用找到的必输局面(后取的玩家有必胜策略)来筛去掉能通过一次操作达该必输局面的其它必胜局面(先取的玩家有必胜策略).最后选出的局面都是必输局面. 构造必胜策略: 如…
NIM(2)“拈”游戏分析 1. 问题 有N块石头和两个玩家A和B,玩家A先将石头分成若干堆,然后按照BABA……的顺序不断轮流取石头,能将剩下的石头一次取光的玩家获胜.每次取石头时,每个玩家只能从若干堆石头中任选一堆,取这一堆石头中任意数目(大于1)个石头. 请问:玩家A有必胜策略吗?要怎么分配和取石头才能保证自己有把握取胜? 2. 解法与分析 据说,该游戏起源于中国,英文名字叫做“NIM”,是由广东话“拈”(取物之意)音译而来,经由当年到美洲打工的华人流传出去,这个游戏一个常见的变种是将十二…
POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the pasture. He measures the fence and finds that he needsN (1 ≤ N ≤ 20,000) planks of wood, each having some integer lengthLi (1 ≤ Li ≤ 50,000) units. He the…
[POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted: 2222 Description Consider a single-elimination football tournament involving 2n teams, denoted 1, 2, -, 2n. In each round of the tournament, all tea…
Poj 3613 Cow Relays (图论) 题目大意 给出一个无向图,T条边,给出N,S,E,求S到E经过N条边的最短路径长度 理论上讲就是给了有n条边限制的最短路 solution 最一开始想到是的去直接统计最短路经过了多少条边,结果,,, 还是太年轻了... 不过,看数据范围只有1000,那么floyd是首选 回顾Floyd算法流程,其中的i到j松弛操作是通过k完成的 那么松弛一次就利用一个k点,我现在要经过n条边,那么松弛n次即可 详细说就是更新一次之后,把f[i][j]拷贝到原来的…
Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which 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 provide…
D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Submit Status Practice POJ 1251 Description The Head Elder of the tropical island of Lagrishan has a problem. A burst of foreign aid money was spent on extr…