简单的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. 《Linux shell编程中 diff与vimdif的使用》RHEL6

    linux比较2个文件的区别有两个命令: (1)diff (2)vimdiff cp /etc/grub.conf hello 在hello文件的末尾添加zhangsan 使用diff比较2个文件的区 ...

  2. window store app 附件读取

    public static async Task<bool> DisplayApplicationPicker(string folderName, string fileName) { ...

  3. 推荐一些C#相关的网站、资源和书籍

    一.网站 1.http://msdn.microsoft.com/zh-CN/ 微软的官方网站,C#程序员必去的地方.那里有API开发文档,还有各种代码.资源下载. 2.http://social.m ...

  4. struts2 type="redirect"源码解析

    首先解释一下几个名词: request.getRequestDispatcher()是请求转发,前后页面共享一个request ; response.sendRedirect()是重新定向,前后页面不 ...

  5. 关于PHP Websocket 错误: "stream_select(): You MUST recompile PHP with a larger value of FD_SETSIZE" 的解决方案

    最近在使用Ratchet (一个PHP websocket框架)改造一个PHP网站的时候,出现了错误: "It is set to 1024, but you have descriptor ...

  6. 【转载】Powershell设置世纪互联Office365嵌套组发送权限

    Start-Transcript ".\Set-GroupSendPermisionLog.txt" -Force function Get-DLMemberRecurse { $ ...

  7. Splitter

    <!DOCTYPE html> <html> <head> <title>PDemo</title> </head> <b ...

  8. libcurl

    一.LibCurl基本编程框架 二.一些基本的函数 三.curl_easy_setopt函数部分选项介绍 四.curl_easy_perform 函数说明(error 状态码) 五.libcurl使用 ...

  9. ios上取得设备唯一标志的解决方案

    iOS 7中苹果再一次无情的封杀mac地址,现在已经不能获取ios7设备的物理地址.那么在开发中如何才能标识设备的唯一性呢?apple公司提供的方法是通过keychain来存一些标志信息,然后通过存的 ...

  10. ios按钮点击后翻转效果

    代码是网上找到的,不过找到的时候直接复制下来不能用,稍微整理下,为和我一样水平的菜鸟观摩一下下. (1)引入“QuartzCore.framework”库,头部引用. #include<Quar ...