1. 大意:有n堆石子,每堆石子个数已知,两人轮流从中取石子,
  2. 每次可取的石子数x满足x属于集合S(k) = {s1,s2,s3...sk-1},问先拿者是否有必胜策略?

裸nim,可以用记忆化搜索。

 #include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<string>
#include<algorithm>
int sg[],s[],k,T,m,x;
void get(int x){
if (sg[x]!=-) return;
bool mark[];
memset(mark,,sizeof mark);
int tmp;
for (int i=;i<=k;i++){
tmp=x-s[i];
if (tmp>=){
if (sg[tmp]==-) get(tmp);
mark[sg[tmp]]=;
}
}
for (int i=;;i++)
if (mark[i]==) {
sg[x]=i;
return;
}
}
int main(){
while (~scanf("%d",&k)){
if (k==) return ;
for (int i=;i<=k;i++)
scanf("%d",&s[i]);
for (int i=;i<=;i++)
sg[i]=-;
scanf("%d",&T);
while (T--){
scanf("%d",&m);
int ans=;
for (int i=;i<=m;i++){
scanf("%d",&x);
if (sg[x]==-) get(x);
ans^=sg[x];
}
if (ans) printf("W");else printf("L");
}
printf("\n");
}
}

poj2960 S-Nim的更多相关文章

  1. 【poj2960】 S-Nim

    http://poj.org/problem?id=2960 (题目链接) 题意 经典Nim游戏,只是给出了一个集合S,每次只能取S[i]个石子. Solution ${g(x)=mex\{SG(x- ...

  2. 【Poj2960】S-Nim & 博弈论

    Position: http://poj.org/problem?id=2960 List Poj2960 S-Nim List Description Knowledge Solution Noti ...

  3. 博弈论基础之sg函数与nim

    在算法竞赛中,博弈论题目往往是以icg.通俗的说就是两人交替操作,每步都各自合法,合法性与选手无关,只与游戏有关.往往我们需要求解在某一个游戏或几个游戏中的某个状态下,先手或后手谁会胜利的问题.就比如 ...

  4. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  5. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  6. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  7. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  8. 【SRM】518 Nim

    题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...

  9. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  10. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

随机推荐

  1. 使用Keil软件编写汇编源程序应注意事项

    1)一定要使用微软的txt文本编辑器,否则键入逗号时编译通不过.应该是这个样('),不该是这个样(,). 2) 用数字做标号时,前面一定要加一个英文字母,否则编译通不过. 3) 有时编译通过的.asm ...

  2. webservice的几个简单概念

    1.什么是JAX-WS? http://baike.baidu.com/view/1865210.htm?fr=aladdin 2.什么是JAX-RPC? http://baike.baidu.com ...

  3. bzoj 1191

    http://www.lydsy.com/JudgeOnline/problem.php?id=1191 二分+二分图匹配. 首先二分可以答对前mid道题,然后做二分图. 左边是题目,右边是锦囊. 做 ...

  4. PHP 面向对象中常见关键字使用(final、static、const和instanceof)

    PHP 面向对象中常见关键字的使用: 1.final :final关键字可以加在类或者类中方法之前,但是不能使用final标识成员属性. 作用: 使用final标识的类,不能被继承. 在类中使用fin ...

  5. myeclipse实现Servlet实例(2) 继承GenericServet类实现,需要重写service方法

    1.在myeclipse新建web project,配置Tomcat(在myeclipse的Window--preferences) 2.然后在src新建servlet文件( 此处放在com.tsin ...

  6. EL表达式使用之类switch语句

    http://blacksonny.iteye.com/admin/blogs/1879878

  7. Head First Html 与 Css 截图

    1.认识HTML web语言 2.深入了解超文本 HTML中的"HT" 3. 构建模块 web页面建设 4. 连接起来 5. 认识媒体,为页面添加图像 6. 严肃的HTML标准及其 ...

  8. python ctypes小例子

    import time import ctypes import ctypes.wintypes SEE_MASK_NOCLOSEPROCESS = 0x00000040 SEE_MASK_INVOK ...

  9. 使用IDEA动态调试smali代码

    原创,转载请注明出处. 一般java ide(如eclipse.idea)都可用来进行smali的动态调试,这里选择IDEA. 第1步:使用apktool反编译apk java -jar apktoo ...

  10. [Javascript] Web APIs: Persisting browser data with window.localStorage

    Local Storage is a native JavaScript Web API that makes it easy to store and persist data (as key-va ...