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. HTML5中class选择器属性的解释

    设置有class属性值的元素,可以被css中的选择器调用,也可以在javascript中以getElementsByClassName()方法调用. 可以给各个元素添加class而且名称可以相同与id ...

  2. gradle命令

    gradle tasks 可以显示gradle可以做的任务. gradle build 就会生成jar包. build和clean install的作用是否一致?

  3. CSS实现垂直居中的常用方法

    在前端开发过程中,盒子居中是常常用到的.其中 ,居中又可以分为水平居中和垂直居中.水平居中是比较容易的,直接设置元素的margin: 0 auto就可以实现.但是垂直居中相对来说是比较复杂一些的.下面 ...

  4. 使用FileResult返回浏览器文件及乱码问题解决

    一.向客户端发送文件方法 Asp.Net 中返回文件方法 public void TxtFile(string filename) { //html文件 string path = @"E: ...

  5. Android实用代码块

    通过反射实现Menu显示图标 @Override public boolean onCreateOptionsMenu(Menu menu) { setIconEnable(menu, true); ...

  6. Property type 'id<tabBarDelegate>' is incompatible with type 'id<UITabBarDelegate> _Nullable' inherited from 'UITabBar'

    iOS报错:Property type 'id' is incompatible with type 'id _Nullable' inherited from 'UITabBar' 如图: 可能原因 ...

  7. Java反射 - 1(得到类对象的几种方法,调用方法,得到包下的所有类)

    通过反射获得对象的方法 准备工作: 有一个User类如下 package o1; /** * Created by yesiming on 16-11-19. */ public class User ...

  8. java事件处理4(焦点,键盘

    FocusEvent焦点事件 接口 addFocusListener(FocusListener listener) 有两个方法 public void focusGains(FocusEvent e ...

  9. createwindow

    WNDCLASS wndclass; wndclass.hbrBackground=(HBRUSH)getstockobject(WHITE_BRUSH); wndclass.hCursor=Load ...

  10. C#操作Excel开发报表系列整理(转)

    C#操作Excel进行报表开发系列共写了七篇,也已经有很久没有新东西了,现在整理一下,方便以后查阅,如果有写新的,会同时更新.需要注意的是因为Office的版本不同,实际的代码可能会有所不同,但是都是 ...