也算是一道模板题吧,只需按照SG函数的定义求出每个值的SG,然后异或就可以了。

 #include <iostream>
#include <cstdio>
#include <algorithm> using namespace std;
const int N=;
int sg[N];
bool vis[N];
int k,s[];
int p[],top;
int work(int w){
int mi=,i;
for(i=;i<=k;i++){
if(w-s[i]>=)
p[++top]=sg[w-s[i]];
}
// if(w==2)
// printf("%d\n",p[0]);
sort(p,p+top+);
for(i=;i<=top;i++){
if(p[i]==mi)
mi++;
else if(p[i]>mi)
break;
}
return mi;
}
char ans[],tot;
int main(){
int i;
while(scanf("%d",&k)!=EOF){
if(!k) break;
// memset(sg,-1,sizeof(sg));
// memset(vis,false,sizeof(vis));
sg[]=;
for(i=;i<=k;i++){
scanf("%d",&s[i]);
}
for(i=;i<=;i++){
top=-;
sg[i]=work(i);
// if(i<=12)
// printf("%d ",sg[i]);
}
// printf("\n");
int n,tmp; tot=-;
scanf("%d",&k);
for(i=;i<=k;i++){
scanf("%d",&n);
int anst=;
for(int j=;j<=n;j++){
scanf("%d",&tmp);
anst=(anst^sg[tmp]);
}
if(!anst)
ans[++tot]='L';
else ans[++tot]='W';
}
for(i=;i<=tot;i++)
printf("%c",ans[i]);
printf("\n");
}
return ;
}

POJ 2960的更多相关文章

  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. POJ 2960 S-Nim<博弈>

    链接:http://poj.org/problem?id=2960 #include<stdio.h> #include<string.h> ; ; int SG[N];//S ...

  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 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...

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

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

  7. hdu 1536/1944 / POJ 2960 / ZOJ 3084 S-Nim 博弈论

    简单的SG函数应用!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #inclu ...

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

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

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

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

随机推荐

  1. android:autoLink

    android:autoLink 显示URL链接 TextView识别链接的方式有两种,一种是自动识别链接和HTML解析链接 1)自动识别链接 <!-- android:autoLink=&qu ...

  2. day02_12/12/2016_bean的实例化之静态工厂方式

  3. ubuntu 安装redis以及phpredis

    一.安装redis 1. 去百度搜索 redis,然后去靠谱的地方下载最新的redisxxx.tar.gz 2. 解压后,sudo make 3. sudo make install 4. //安装完 ...

  4. Java 6中类路径ClassPath对通配符的支持

    在java 6之前,如果我们的应用依赖多个jar包,通常是将所有jar包文件枚举设置到环境变量CLASSPATH或者命令行参数-classpath(-cp)中.通常我们需要写一段shell脚本实现该功 ...

  5. SQL基本操作——约束

    我们将主要探讨以下几种约束: 1.NOT NULL 2.UNIQUE 3.PRIMARY KEY 4.FOREIGN KEY 5.CHECK 6.DEFAULT SQL NOTNULL约束:NOT N ...

  6. [Windows Server 2012] 手工破解MySQL密码

    ★ 欢迎来到[护卫神·V课堂],网站地址:http://v.huweishen.com★ 护卫神·V课堂 是护卫神旗下专业提供服务器教学视频的网站,每周更新视频.★ 本节我们将带领大家:破解MySQL ...

  7. Twisted web开发教程

    最近在网上看到一篇twisted web开发文章,将它实践了一下,twisted 提供基本的url路由 和 控制器,模板与模型需要外部扩展 1.目录浏览 2.get请求 3.url路由 4.接受带参数 ...

  8. codeforces_734C_二分

    C. Anton and Making Potions time limit per test 4 seconds memory limit per test 256 megabytes input ...

  9. Concurrency and Application Design

    Concurrency and Application Design In the early days of computing, the maximum amount of work per un ...

  10. 扩增子分析QIIME2-4分析实战Moving Pictures

    本示例的的数据来自文章<Moving pictures of the human microbiome>,Genome Biology 2011,取样来自两个人身体四个部位五个时间点   ...