链接:http://poj.org/problem?id=2960

 #include<stdio.h>
#include<string.h>
const int N = ;
const int M= ;
int SG[N];//SG[i]记录一堆i颗石子的SG状态
int s[M];//存储可选取的石子数目集合
int k;//s[]集合中的元素个数
int mex(int x)
{
if( SG[x]!=- )return SG[x];
bool vi[N]={};
for( int i=; i<k; ++ i ){
if( s[i] <= x ){
vi[mex(x-s[i])]=;
}
}
int i=;
while(vi[i])++i;
return SG[x]=i;
}
int main()
{
while(scanf("%d",&k)!=EOF)//可选集合中的元素个数
{
if(k==)break;
int i,ans;
for(i=; i<k; i++)
scanf("%d",&s[i]);
memset(SG,-,sizeof(SG));
SG[]=;
int m;
scanf("%d",&m);//测试组数
while(m--)
{
ans=;
int l;
scanf("%d",&l);//石子堆数
while(l--)
{
int x;
scanf("%d",&x);//当前堆石子数目
if(SG[x]==-)
SG[x]=mex(x);
ans=ans^SG[x];
} if(ans==)printf("L");
else
printf("W");
} printf("\n");
} return ;
}

POJ 2960 S-Nim<博弈>的更多相关文章

  1. poj 2960 S-Nim

    S-Nim Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4113   Accepted: 2158 Description ...

  2. HDU3544 Alice's Game && POJ 2960 S-Nim(SG函数)

    题意: 有一块xi*Yi的矩形巧克力,Alice只允许垂直分割巧克力,Bob只允许水平分割巧克力.具体来说,对于Alice,一块巧克力X i * Y i,只能分解成a * Y i和b * Y i其中a ...

  3. S-Nim POJ - 2960 Nim + SG函数

    Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> ...

  4. POJ 2960 博弈论

    题目链接: http://poj.org/problem?id=2960 S-Nim Time Limit: 2000MS Memory Limit: 65536K 问题描述 Arthur and h ...

  5. POJ 2960 S-Nim (sg函数)

    题目链接:http://poj.org/problem?id=2960 题目大意:给定数组S,接下来给出m个游戏局面.游戏局面是一些beads堆,先给出堆数,然后是每一堆中beads的数目.游戏规则是 ...

  6. POJ 2960 S-Nim 博弈论 sg函数

    http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...

  7. poj 2960 S-Nim(SG函数)

    S-Nim Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 3694   Accepted: 1936 Description ...

  8. Georgia and Bob POJ - 1704 阶梯Nim

    $ \color{#0066ff}{ 题目描述 }$ Georgia and Bob decide to play a self-invented game. They draw a row of g ...

  9. poj 2960 S-Nim【SG函数】

    预处理出SG函数,然后像普通nim一样做即可 #include<iostream> #include<cstdio> using namespace std; const in ...

随机推荐

  1. 用C#编写游戏脚本

    大学宿舍玩游戏的时候,为了简化重复的键鼠动作,有学习过按键精灵和TC脚本开发工具,并做了一些小脚本,基本达到了当时的需求.不知不觉,已经毕业了3年了,无聊之余又玩起了游戏,对于一些无趣的重复行为,于是 ...

  2. JavaScript内置对象

    对象概述 JavaScript是一种基于对象的脚本语句,而不是面向对象的编程语言.对象就是客观世界存在的实体,具有属性和方法两方面特性. 访问对象的属性和方法的方式如下: 对象名.属性 对象名.方法名 ...

  3. 关于java.lang.String理解中的一些难点

    最近温习java的一些基础知识,发现以往对String对象认识上的一些不足.特汇总如下,主要是帮助记忆,如能对其他朋友有些启发,不胜欣喜. String在JVM中内存驻留问题 JVM的常量区(Cons ...

  4. Solum入门知识(编辑中)

    概要 参考:https://wiki.openstack.org/wiki/Solum An OpenStack project designed to make cloud services eas ...

  5. alter table <表名 > add constraint <主键名>用法

    alter table <表名 > add constraint  <主键名>用法介绍 1.主键约束: 要对一个列加主键约束的话,这列就必须要满足的条件就是分空 因为主键约束: ...

  6. Java之注解

    package com.demo.test; import java.lang.annotation.Documented; import java.lang.annotation.ElementTy ...

  7. Loadrunner:安装LR11.0破解步骤及License

    破解步骤: 1.关闭LR相关程序 2.运行LicenseDelete程序,清除LR原来的License 3.将lm70.dll和mlr5lprg.dll这两个文件复制并粘贴到LR安装目录下的bin文件 ...

  8. JPA 批量新增

    1. 在实现类 增加 EntityManager 注入 private EntityManager em; @PersistenceContext(name = "EntityManager ...

  9. Data URL

    Data URL 早在 1995 年就被提出,那个时候有很多个版本的 Data URL Schema 定义陆续出现在 VRML 之中,随后不久,其中的一个版本被提上了议案——将它做个一个嵌入式的资源放 ...

  10. GUI_DOWNLOAD参数说明

    对FUNCTION: GUI_DOWNLOAD中某些参数的用法.       call function 'GUI_DOWNLOAD'     exporting *     BIN_FILESIZE ...