题目链接:http://acm.hdu.edu.cn/showproblem.php?

pid=1944

pid=1536">
http://acm.hdu.edu.cn/showproblem.php?pid=1536

给定每一次能够取的石头数,给定非常多种情况,每一种情况有若干堆石头,推断先手胜负。

SG函数打表,然后直接抑或。推断结果是否为0。第一次写SG函数,贴个代码,慢慢理解。

代码:

/* ***********************************************
Author :rabbit
Created Time :2014/7/4 12:00:18
File Name :3.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
int f[110],d[20010],g[110];
int SG(int p,int k){
memset(g,0,sizeof(g));
for(int i=0;i<k;i++){
int t=p-f[i];
if(t<0)break;
if(d[t]==-1)d[t]=SG(t,k);
g[d[t]]=1;
}
for(int i=0;;i++)
if(!g[i])return i;
}
int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int n;
while(~scanf("%d",&n)){
if(!n)break;
for(int i=0;i<n;i++)scanf("%d",&f[i]);
sort(f,f+n);
memset(d,-1,sizeof(d));
d[0]=0;
for(int i=1;i<=10010;i++)
d[i]=SG(i,n);
int m;
scanf("%d",&m);
while(m--){
int k;
scanf("%d",&k);
int sum=0,v;
while(k--){
scanf("%d",&v);
sum^=d[v];
}
if(!sum)printf("L");
else printf("W");
}
puts("");
}
return 0;
}

SG 函数初步 HDU 1536 &amp;&amp; HDU 1944的更多相关文章

  1. (巴什博弈 sg函数入门1) Brave Game -- hdu -- 1846

    链接: http://acm.hdu.edu.cn/showproblem.php?pid=1846 首先来玩个游戏,引用杭电课件上的: (1) 玩家:2人:(2) 道具:23张扑克牌:(3) 规则: ...

  2. hdu 3032 Nim or not Nim? sg函数 难度:0

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  3. S-Nim HDU 1536 博弈 sg函数

    S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...

  4. HDU 1536 sg函数

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

  5. hdu 1536 SG函数模板题

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

  6. HDU 1536 S-Nim (组合游戏+SG函数)

    题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...

  7. hdu 2147 SG函数打表(手写也可以) 找规律

    kiki's game Time Limit: 5000/1000 MS (Java/Others)    Memory Limit: 40000/1000 K (Java/Others) Total ...

  8. hdu 1848 简单SG函数

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...

  9. HDU 5724 Chess(SG函数+状态压缩)

    http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...

随机推荐

  1. OSAL工作机制分析

    协议栈代码main()函数分析 ZMain文件->ZMain.c->main()  在这里我们重点了解osal_start_system()函数 int main( void ) { // ...

  2. 8 个基于 Lucene 的开源搜索引擎推荐

    Lucene是一种功能强大且被广泛使用的搜索引擎,以下列出了8种基于Lucene的搜索引擎,你可以想象它们有多么强大. 1. Apache Solr Solr 是一个高性能,采用Java5开发,基于L ...

  3. winform中RichTextBox在指定光标位置插入图片

    代码如下: //获取RichTextBox控件中鼠标焦点的索引位置 int startPosition = this.richTextBox1.SelectionStart; //从鼠标焦点处开始选中 ...

  4. C#窗体读取EXCEL存入SQL数据库

    windows窗体上放了一个Textbox1,2个按钮button1和button2~按button1选择excel文件~按button2进行相关处理 Code Snippet private  vo ...

  5. python3 map,filter和列表推导式

    num_list = [11,2,-33,10,7,3,5,43] 1.filter  函数 获取num_list大于5的元素,并返回列表 用lambda表达式实现: # 在python2 中 fil ...

  6. 【Python】无须numpy,利用map函数与zip(*)函数对数组转置(转)

    http://blog.csdn.net/yongh701/article/details/50283689 在Python的numpy中,对类似array=[[1,2,3],[4,5,6],[7,8 ...

  7. .NET Framework 工具

    您可以使用 .NET Framework 工具轻松创建.部署和管理面向 .NET Framework 的应用程序和组件. 此节中介绍的大部分 .NET Framework 工具将自动随 Visual ...

  8. ASP入门(十七)-ASP #include

    通过使用 #include 指令,您可以在服务器执行 ASP 文件之前,把另一个 ASP 文件的内容插入到这个 ASP 文件中. 如何使用 #include 指令 这里有一个名为 mypage.asp ...

  9. Install SVN (Subversion) Server on Fedora 20/19, CentOS/Red Hat (RHEL) 6.5/5.10

    Install SVN (Subversion) Server on Fedora 20/19, CentOS/Red Hat (RHEL) 6.5/5.10 Updated by JR on Mar ...

  10. SpringBoot 启动错误搜集

    Spring Boot:The Bean Validation API is on the classpath but no implementation could be found https:/ ...