poj2960 S-Nim
- 大意:有n堆石子,每堆石子个数已知,两人轮流从中取石子,
- 每次可取的石子数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的更多相关文章
- 【poj2960】 S-Nim
http://poj.org/problem?id=2960 (题目链接) 题意 经典Nim游戏,只是给出了一个集合S,每次只能取S[i]个石子. Solution ${g(x)=mex\{SG(x- ...
- 【Poj2960】S-Nim & 博弈论
Position: http://poj.org/problem?id=2960 List Poj2960 S-Nim List Description Knowledge Solution Noti ...
- 博弈论基础之sg函数与nim
在算法竞赛中,博弈论题目往往是以icg.通俗的说就是两人交替操作,每步都各自合法,合法性与选手无关,只与游戏有关.往往我们需要求解在某一个游戏或几个游戏中的某个状态下,先手或后手谁会胜利的问题.就比如 ...
- [LeetCode] Nim Game 尼姆游戏
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- LeetCode 292. Nim Game
Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...
- 【SRM】518 Nim
题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
随机推荐
- selenium太有爱,我已离不开!!!
自动化测试,超有用. PROXY,PLUGIN,PROFILE,WINDOWS HANDLE个个搞定!!! from selenium import webdriver from selenium.c ...
- ASM-51 宏汇编使用手册
A51与ASM51基本相同 ASM-51 宏汇编主要用来开发Inter8051系列单片机,它具有宏处理,数据处理,列表处理和条件处理等多种功能.源程序的编写完全采用 Inter标准助记符和行格式. ...
- 关于IoCallDriver
通常我们所知IoCallDriver是把irp传递给下一层设备,传递到底是什么意思呢?IoCallDriver中实际调用了IopfCallDriver,其代码如下:NTSTATUSFORCEINLIN ...
- BZOJ3016: [Usaco2012 Nov]Clumsy Cows
3016: [Usaco2012 Nov]Clumsy Cows Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 71 Solved: 52[Submi ...
- puppet证书重申
- 自制USB wifi信号放大天线
这是我的usb wifi天线第一个版本,灵感来自: http://www.instructables.com/id/EQARE4I72GEPUCHTHU/ http://www.usbwifi.orc ...
- maven plugin在tomcat 热部署
前言: 此处的方法适用于tomcat6 和 tomcat7,对于最新的tomcat8还没有进行过測试,有兴趣的同学能够自己測一下. 总共分为五步: 1.在tomcat中配置用户权限,即 ...
- 选择Android还是IOS开发?
选择Android还是IOS? 随着移动互联网的如日中天,涌现了越来越多的开发者.IOS优秀的用户体验,Android极高的用户群,这对于开发者来说陷入了选择困难的境地,尤其是新入门的开发者,精力有限 ...
- [RxJS] Updating Data with Scan
You often need to update the data flowing through the stream with custom logic based on what you nee ...
- Smack+Openfire 接收和发送文件
转载请注明出处:http://blog.csdn.net/steelychen/article/details/37958839 发送文件须要提供准确的接收放username称(例:user2@192 ...