简单的SG函数应用!!!

代码如下:

 #include<iostream>
#include<stdio.h>
#include<algorithm>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
int sg[],k,a[];
int getsg(int x)
{
if(sg[x]!=-) return sg[x];
if(x-a[]<) return sg[x]=;
bool vis[];
memset(vis,,sizeof(vis));
for(int i=;i<k&&x-a[i]>=;i++){
vis[getsg(x-a[i])]=;
}
for(int i=;;i++)
if(!vis[i])
return sg[x]=i;
}
int main(){
int i,j,n,m,ans,s;
while(scanf("%d",&k)&&k){
memset(sg,-,sizeof(sg));
sg[]=;
for(i=;i<k;i++) scanf("%d",&a[i]);
sort(a,a+k);
scanf("%d",&n);
for(i=;i<n;i++){
scanf("%d",&m);
ans=;
for(j=;j<m;j++){
scanf("%d",&s);
ans^=getsg(s);
}
if(!ans) cout<<"L";
else cout<<"W";
}
cout<<endl;
}
return ;
}

hdu 1536/1944 / POJ 2960 / ZOJ 3084 S-Nim 博弈论的更多相关文章

  1. HDU 1536 & 1944

    http://acm.hdu.edu.cn/showproblem.php?pid=1536 http://acm.hdu.edu.cn/showproblem.php?pid=1944 一样的题 题 ...

  2. HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)

    Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...

  3. hdu 1536&&1944 S-Nim sg函数 难度:0

    S-Nim Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submi ...

  4. hdu 2486/2580 / poj 3922 A simple stone game 博弈论

    思路: 这就是K倍动态减法游戏,可以参考曹钦翔从“k倍动态减法游戏”出发探究一类组合游戏问题的论文. 首先k=1的时候,必败态是2^i,因为我们把数二进制分解后,拿掉最后一个1,那么会导致对方永远也取 ...

  5. POJ 1562 && ZOJ 1709 Oil Deposits(简单DFS)

    题目链接 题意 : 问一个m×n的矩形中,有多少个pocket,如果两块油田相连(上下左右或者对角连着也算),就算一个pocket . 思路 : 写好8个方向搜就可以了,每次找的时候可以先把那个点直接 ...

  6. HDU 1815, POJ 2749 Building roads(2-sat)

    HDU 1815, POJ 2749 Building roads pid=1815" target="_blank" style="">题目链 ...

  7. poj 2960 S-Nim

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

  8. HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径)

    HDU 1069 Monkey and Banana / ZOJ 1093 Monkey and Banana (最长路径) Description A group of researchers ar ...

  9. HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP)

    HDU 1686 Oulipo / POJ 3461 Oulipo / SCU 2652 Oulipo (字符串匹配,KMP) Description The French author George ...

随机推荐

  1. C# 枚举操作扩展类

    using System; using System.Linq; using System.ComponentModel; namespace Demo.Common { /// <summar ...

  2. zedboard 驱动理解

    1 驱动程序的编写   驱动是LINUX开发的必经之路,应用层对底层的调用经过了库与内核,内核下面才是驱动层,当你在应用程序执行对底层的控制时,驱动程序为你的控制提供了接口,或者说是策略. #incl ...

  3. 开始ubuntu 14.04 的装X模式---终端模式下中文输入,听歌,上irc 开启framebuffer看电影 截图

    先上图吧 卡卡的全是在tty1 下的操作,看电影,听歌,截图 ,看图  ,上irc 等等,相当适合在小白面前装屁! 需要安装的软件: 为了能正常显示中文:安装fbterm sudo apt-get i ...

  4. CSS3实现半像素边框

    一.思路 普通的1px黑色实线边框: border: 1px solid #000; 半像素边框当然不是简单地把1px改为0.5px(没测试过,可能会被解析成1或者0),border-width的值只 ...

  5. 分享:linux下apache服务器的配置和管理

    linux下apache服务器的配置和管理. 一.两个重要目录: Apache有两个重要的目录:1.配置目录/etc/httpd/conf:2.文档目录/var/www: 二.两种配置模式: Apac ...

  6. php错误收集

    1.Notice: Undefined offset: 1 in F:\www\my\test.php on line 39,原因offset:接下去的数字是出错的数组下标,一般是超出了数组的取值范围 ...

  7. TextView文字排版问题:

    本文转载自:http://blog.sina.com.cn/s/blog_821e2bb101011803.html textview自动换行导致混乱的原因----半角字符与全角字符混乱所致!一般情况 ...

  8. 使用dxNavBar动态创建应用程序菜单

    一.如何动态创建dxNavBar内容: function TMain.GetAcitonByCaption(const aCategory,aCaption: string): Integer; va ...

  9. Mysql主从同步(复制)

    目录: mysql主从同步定义      主从同步机制 配置主从同步      配置主服务器      配置从服务器 使用主从同步来备份      使用mysqldump来备份      备份原始文件 ...

  10. cadence 机械孔的制作

    在平时画PCB的时候,会用到安装孔,好多人就是找个过孔,在原理图中连接GND,这样使用也可以,下面介绍一种正经机械孔的制作方法(自己摸索的),制作一个孔径为3mm的安装孔. 1 打开pad desig ...