题意:

K个数,s1...sk。

m个状态,对于某一个状态,有L堆石子,每人每次取的石子个数只能是s1...sk的一个,且只能在一堆中取。

输出m个状态是先手胜还是先手败,先手胜输出W,否则输出L。

输入格式及数据范围:

For each test case: The first line contains a number k (0 < k ≤ 100) describing the size of S, followed by k numbers si (0 < si ≤ 10000) describing S. The second line contains a number m (0 < m ≤ 100) describing the number of positions to evaluate. The next m lines each contain a number l (0 < l ≤ 100) describing the number of heaps and l numbers hi (0 ≤ hi ≤ 10000) describing the number of beads in the heaps. 
The last test case is followed by a 0 on a line of its own.

思路:

对于每个小堆求sg1...sgL(用记忆搜),则某个状态的SG=sg1^...^sgL。 SG概念题。

代码:

int sg[10005];
int k,m,l;
int s[105];
char ss[105]; void dfs(int x){
bool vis[10005] = {0}; if(sg[x]!=-1)
return; rep(i,1,k){
if(x>=s[i]){
if(sg[x-s[i]]==-1) dfs(x-s[i]);
vis[sg[x-s[i]]] = true;
}
}
for(int i=0;;++i){
if(!vis[i]){
sg[x]=i;
return;
}
}
} int main(){
int x; while(scanf("%d",&k),k){
rep(i,1,k) scanf("%d",&s[i]);
mem(sg,-1); sg[0]=0; scanf("%d",&m);
int geshu=0;
while(m--){
scanf("%d",&l);
int ans=0;
rep(i,1,l){
scanf("%d",&x);
if(sg[x]==-1) dfs(x);
ans=ans^sg[x];
}
if(!ans)
ss[++geshu]='L';
else
ss[++geshu]='W';
}
rep(i,1,geshu) printf("%c",ss[i]); cout<<endl;
}
}

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

  1. poj 2311 Cutting Game (SG)

    题意: 有一张W*H的纸片. 每人每次可以横着撕或者竖着撕,先撕出1*1那一方胜. 数据范围: W and H (2 <= W, H <= 200) 思路: 很好抽象出游戏图的模型,用SG ...

  2. 【HDU3032】Nim or not Nim?(博弈论)

    [HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...

  3. POJ 3669 Meteor Shower(流星雨)

    POJ 3669 Meteor Shower(流星雨) Time Limit: 1000MS    Memory Limit: 65536K Description 题目描述 Bessie hears ...

  4. 第1章 游戏之乐——NIM(3)两堆石头的游戏

    NIM(3)两堆石头的游戏 1. 问题描述 假设有两堆石头,有两个玩家会根据如下的规则轮流取石头:每人每次可以从两堆石头中各取出数量相等的石头,或者仅从一堆石头中取出任意数量的石头:最后把剩下的石头一 ...

  5. 第1章 游戏之乐——NIM(2)“拈”游戏分析

    NIM(2)“拈”游戏分析 1. 问题 有N块石头和两个玩家A和B,玩家A先将石头分成若干堆,然后按照BABA……的顺序不断轮流取石头,能将剩下的石头一次取光的玩家获胜.每次取石头时,每个玩家只能从若 ...

  6. POJ 3253 Fence Repair (优先队列)

    POJ 3253 Fence Repair (优先队列) Farmer John wants to repair a small length of the fence around the past ...

  7. 【POJ 3071】 Football(DP)

    [POJ 3071] Football(DP) Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 4350   Accepted ...

  8. Poj 3613 Cow Relays (图论)

    Poj 3613 Cow Relays (图论) 题目大意 给出一个无向图,T条边,给出N,S,E,求S到E经过N条边的最短路径长度 理论上讲就是给了有n条边限制的最短路 solution 最一开始想 ...

  9. HDU 3032 Nim or not Nim? (sg函数求解)

    Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...

  10. POJ 1251 Jungle Roads (prim)

    D - Jungle Roads Time Limit:1000MS     Memory Limit:10000KB     64bit IO Format:%I64d & %I64u Su ...

随机推荐

  1. mogoose 创建数据库并增删改查

    下载 npm i mongoose -s 连接数据库 const mongoose = require("mongoose"); mongoose.connect(dbURL); ...

  2. 如何在Ubuntu 18.04安装Git

    在Ubuntu 18.04安装Git 更新apt包列表 apt-get update -y apt-get upgrade -y 安装Git: apt install git 检查Git版本 git ...

  3. iPhone发布内测程序的方法

    iPhone是封闭系统,不像android手机可以自行安装apk,所以iPhone手机发布内测程序相对来说复杂一些. 越狱安装 如果测试用户的机器已经越狱,那就简单了,直接打包成ipa,用户直接通过9 ...

  4. ARC106E-Medals【hall定理,高维前缀和】

    正题 题目链接:https://atcoder.jp/contests/arc106/tasks/arc106_e 题目大意 \(n\)个员工,第\(i\)个在\([1,A_i]\)工作,\([A_i ...

  5. pandas 基础命令

    参考链接:https://github.com/rmpbastos/data_science/blob/master/_0014_Boost_your_Data_Analysis_with_Panda ...

  6. PyTorch固定参数

    In situation of finetuning, parameters in backbone network need to be frozen. To achieve this target ...

  7. T-SQL——关于表数据的复制插入

    目录 0. 复制表中一列插入到另外一列 1. 复制表结构和数据到自动创建的一张新表中--select into 2. 复制表中一些字段值插入到另外一张表中--insert into 3. 将存储过过程 ...

  8. 关于使用antd-vue的卡片无法设置avatar图标/头像问题的解决方案

    在使用antd-vue的卡片a-card时,遇到无法添加avatar图标/头像的问题,原因出在a-avatar,他不支持webpack图片打包. 上代码:       <a-card hover ...

  9. 修改MySql Root密码(包含忘记密码的方式)

    曾几何时,我也是记得MySQL root密码的人,想要修改root密码还不是轻而易举的事?下面前三种修改改方式都是在记得密码的情况下进行修改,如果你忘记了原本的root,请直接跳至 终极 第一种: 在 ...

  10. react之组件生命周期

    四个阶段 初始化 运行中 销毁 错误处理(16.3以后) 初始化 constructor static getDerivedStateFromProps() componentWillMount() ...