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. 动态规划+滚动数组 -- POJ 1159 Palindrome

    给一字符串,问最少加几个字符能够让它成为回文串. 比方 Ab3bd 最少须要两个字符能够成为回文串 dAb3bAd 思路: 动态规划 DP[i][j] 意味着从 i 到 j 这段字符变为回文串最少要几 ...

  2. javascript內容向上不間斷滾動

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  3. Tomcat: IllegalStateException: No output folder --reference

    Today, I started to create a couple of JSP pages for the server-side part of my MSc thesis project i ...

  4. SQL 结构化查询语言手册

    摘自该学习网站: http://www.w3school.com.cn/sql/ 新学到的几点: and 和or 连用,记得用括号.                2.SQL通配符补充   例如:   ...

  5. tail和head命令

    [root@rhel7 ~]# cat rusky --cat命令查看文件内容 line1 line2 line3 line4 line5 line6 line7 line8 line9 line10 ...

  6. require(),include(),require_once()和include_once()之间的区别

    引用文件的方法有两种:require 及 include. require 的使用方法如 require("file.php"); .这个函数通常放在 PHP 程序的最前面,PHP ...

  7. MySQL -A不预读数据库信息(use dbname 更快)

    mysql数据库预读与不预读数据库信息(use dbname)—Reading table information for completion of table and column names   ...

  8. InstallShield 覆盖安装

    “吾乐吧软件站”提供了很全面详细的InstallShield制作安装包教程(http://www.wuleba.com/23892.html),但是按上面的方法再次制作的升级安装包,安装后会在系统中同 ...

  9. oracle 分布式数据库

    分布式数据库的数据库链路是单向的

  10. epoll模型的et模式和lt模式

    http://www.cppblog.com/peakflys/archive/2012/08/26/188344.html    评论区讨论,唐诗! http://www.cnblogs.com/e ...