也算是一道模板题吧,只需按照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. Django总结一

    HTTPRequest与HTTPresponse 一. 1.互联网两台机器之间通行:ip.端口.协议 - 协议 - HTTP (80) - HTTPS (443) 2.浏览器输入URL一回车返回页面发 ...

  2. HDU 3007 最小圆覆盖 计算几何

    思路: 随机增量法 (好吧这数据范围并不用) //By SiriusRen #include <cmath> #include <cstdio> #include <al ...

  3. ansible基础知识

    安装ansible epel源 第一步: 下载epel源 wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel- ...

  4. 题解报告:hdu 2647 Reward(拓扑排序)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2647 Problem Description Dandelion's uncle is a boss ...

  5. 为什么使用HttpServlet?http协议特点、servlet

    因为只有HttpServlet是基于http协议,实现Servlet接口,而http协议是短连接协议,能够实现客户端访问服务端后,数据交互后 连接自动断开.同时http协议基于tcp.ip协议,封装了 ...

  6. cmd bat 相对命令

    "%~dp0",在BAT中,是不是“相对路径”的意思 (2013-08-21 12:19:32) 转载▼ 标签: 杂谈 分类: C# 0念 零 ,代表你的批处理本身. d p是FO ...

  7. Intent的调用

    //Intent  intent=new Intent();//intent.setClass(MainActivity.this, GPSService.class);//以上二条可以合并成如下一条 ...

  8. React-Native WebView动态加载字体

    背景 使用react-native构建的iOS/Android双端APP,通过WebView加载本地页面,需要根据服务器提供的字体列表实现下载和动态加载. 本地字体检查 有些字体手机操作系统已经提供了 ...

  9. 初学JSP_内置对象

    out内置对象: 表单,表单常用的的提交方式

  10. Django的文件下载

    在实际的项目中很多时候需要用到下载功能,如导excel.pdf或者文件下载,当然你可以使用web服务自己搭建可以用于下载的资源服务器,如nginx,这里我们主要介绍django中的文件下载. 我们这里 ...