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

SG经典题,不多说

// File Name: hdu1536.cpp
// Author: bo_jwolf
// Created Time: 2013年09月30日 星期一 18:23:53 #include<vector>
#include<list>
#include<map>
#include<set>
#include<deque>
#include<stack>
#include<bitset>
#include<algorithm>
#include<functional>
#include<numeric>
#include<utility>
#include<sstream>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cmath>
#include<cstdlib>
#include<cstring>
#include<ctime> using namespace std; const int N = 105 ;
const int MAXN = 10100;
bool vis[MAXN];
int sg[MAXN];
int si[ MAXN ] , n ;
int Getsg( int N )
{//printf( " n = %dn",n );
int hash[105] = {0};
for( int i = 0; i < n && si[i] <= N; ++i )
{
if( sg[N-si[i]] == -1 )
sg[N-si[i]] = Getsg( N - si[i] );
hash[sg[N-si[i]]] = 1;
}
for( int i = 0; ; i++ )
if( !hash[i] )
return i;
} int main(){
int temp , ans , m ;
while( scanf( "%d" , &n ) != EOF && n ){
for( int i = 0 ; i < n ; ++i ){
scanf( "%d" , &si[ i ] ) ;
}
memset( sg , -1 , sizeof( sg ) ) ;
sort( si , si + n ) ;
int Case ;
scanf( "%d" , &Case ) ;
while( Case-- ){
scanf( "%d" , &m ) ;
ans = 0;
for( int i = 0 ; i < m ; ++i ){
scanf( "%d" , &temp ) ;
ans ^= Getsg( temp ) ;
}
if( ans == 0 ) cout << "L" ;
else cout << "W" ;
}
cout << endl ;
}
return 0;
}

S-Nim的更多相关文章

  1. [LeetCode] Nim Game 尼姆游戏

    You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...

  2. CodeForces - 662A Gambling Nim

    http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...

  3. HDU 5795 A Simple Nim 打表求SG函数的规律

    A Simple Nim Problem Description   Two players take turns picking candies from n heaps,the player wh ...

  4. LeetCode 292. Nim Game

    Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...

  5. 【SRM】518 Nim

    题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...

  6. HDU 2509 Nim博弈变形

    1.HDU 2509  2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...

  7. HDU 1907 Nim博弈变形

    1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...

  8. Nim游戏

    目前有3堆石子,每堆石子个数也是任意的,双方轮流从中取出石子,规则如下:1)每一步应取走至少一枚石子:每一步只能从某一堆中取走部分或全部石子:2)如果谁不能取谁就失败. Bouton定理: 必败状态当 ...

  9. HDU 3032 Nim or not Nim (sg函数)

    加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...

  10. 292. Nim Game

    292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on ...

随机推荐

  1. 转 [教程] Unity3D中角色的动画脚本的编写(二)

              在上一篇,我们介绍了有关Animation这个类中的部分方法,我后来想了想,这么介绍也不是个办法(其实有些方法我自己也没用过),该介绍点实际的东西了,毕竟我们是要做东西出来的.那好 ...

  2. 让jquery easyui datagrid列支持绑定嵌套对象

    嵌套对象是指返回的json数据,是对象的某个属性自带有属性.而我们恰恰又需要这个属性,默认情况下easyui的datagrid是不支持绑定嵌套对象的.比如:datagrid的field属性只能为fie ...

  3. Topcoder SRM 637 (Div.2)

    A.GreaterGameDiv2 不能更水 #line 7 "GreaterGameDiv2.cpp" #include<cstdio> #include <c ...

  4. 【转】Multithreaded Python Tutorial with the “Threadworms” Demo

    The code for this tutorial can be downloaded here: threadworms.py or from GitHub. This code works wi ...

  5. lucene实战(第二版)学习笔记

    初识Lucene 构建索引 为应用程序添加搜索功能 Lucene的分析过程

  6. CSS3 字体

    CSS3 @font-face 规则 在 CSS3 之前,web 设计师必须使用已在用户计算机上安装好的字体. 通过 CSS3,web 设计师可以使用他们喜欢的任意字体. 当您您找到或购买到希望使用的 ...

  7. 学习日记-----ORM

    ORM ORM(Object Relation Mapping)对象关系映射 实质:将数据库中 的业务数据用对象的形式表现出来,使用ORM在业务逻辑层和数据访问层之间充当桥梁 核心原则: 简单性 传达 ...

  8. Windows8 正式版最简单的去除桌面水印方法

    方法一: 优点:无需替换文件,无需任何工具,对系统没有副作用缺点:更换主题或者壁纸之后水印再现方法:按住 “win键+P” 进入 “第二屏幕 ”选择 “扩展”再按住 “win键+P” 进入 “第二屏幕 ...

  9. C#中结构的使用

    //声明结构 结构与枚举区别,一个不用声明类型,一个要声明类型 public struct Person { //这里叫字段,做用也是存储内容,变量只可以存一个值,字段可以存多个值 //声明字段前最好 ...

  10. HTML5 web开发时遇到的一个奇葩问题。

    昨天做了一个手机端的H5 页面. 首先就是各种兼容测试,调整修复..一系列操作之后,拿过来N多手机神马华为.小米.三星.水果5.6.plus,一番测试之后.嗯,还不错,稍作等待之后就上线了. 这是分割 ...