S-Nim
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的更多相关文章
- [LeetCode] Nim Game 尼姆游戏
You are playing the following Nim Game with your friend: There is a heap of stones on the table, eac ...
- CodeForces - 662A Gambling Nim
http://codeforces.com/problemset/problem/662/A 题目大意: 给定n(n <= 500000)张卡片,每张卡片的两个面都写有数字,每个面都有0.5的概 ...
- HDU 5795 A Simple Nim 打表求SG函数的规律
A Simple Nim Problem Description Two players take turns picking candies from n heaps,the player wh ...
- LeetCode 292. Nim Game
Problem: You are playing the following Nim Game with your friend: There to stones. The one who remov ...
- 【SRM】518 Nim
题意 \(K(1 \le K \le 10^9)\)堆石子,每堆石子个数不超过\(L(2 \le 50000)\),问Nim游戏中先手必败局面的数量,答案对\(10^9+7\)取模. 分析 容易得到\ ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- HDU 1907 Nim博弈变形
1.HDU 1907 2.题意:n堆糖,两人轮流,每次从任意一堆中至少取一个,最后取光者输. 3.总结:有点变形的Nim,还是不太明白,盗用一下学长的分析吧 传送门 分析:经典的Nim博弈的一点变形. ...
- Nim游戏
目前有3堆石子,每堆石子个数也是任意的,双方轮流从中取出石子,规则如下:1)每一步应取走至少一枚石子:每一步只能从某一堆中取走部分或全部石子:2)如果谁不能取谁就失败. Bouton定理: 必败状态当 ...
- HDU 3032 Nim or not Nim (sg函数)
加强版的NIM游戏,多了一个操作,可以将一堆石子分成两堆非空的. 数据范围太大,打出sg表后找规律. # include <cstdio> # include <cstring> ...
- 292. Nim Game
292. Nim Game You are playing the following Nim Game with your friend: There is a heap of stones on ...
随机推荐
- Android布局文件-错误
View requires API level 14 (current min is 8): <?xml version="1.0" encoding="utf-8 ...
- 解析xml的几种方式
http://blog.csdn.net/smcwwh/article/details/7183869
- git add相关
git add -A stages All git add . stages new and modified, without deleted git add -u stages modified ...
- log4j日志输出使用教程
Log4j是帮助开发人员进行日志输出管理的API类库.它最重要的特点就可以配置文件灵活的设置日志信息的优先级.日志信息的输出目的地以及日志信息的输出格式.Log4j除了可以记录程序运行日志信息外还有一 ...
- 如何启动Service,如何停用Service(转)
如何启用Service,如何停用Service Android中的服务和windows中的服务是类似的东西,服务一般没有用户操作界面,它运行于系统中不容易被用户发现,可以使用它开发如监控之类的程序.服 ...
- rtmp协议介绍
概述: •tcp建立连接. •rtmp握手. •客户端与服务器对建立rtmp连接达成一致. •创建rtmp流 •客户端与服务器对play或者Publish达成一致. •客户端开始传送数据到服务器. • ...
- Centos下删除文件名乱码文件
centos下通过rm命令来删除文件,但是如果要删除文件名乱码的文件,就不能直接使用rm命令了,因为压根就无法输出文件名来.不过借助find命令可以实现对其删除.在linux下对于每个文件都一个对应的 ...
- 【行为型】Command模式
命令模式是指将用户的请求封装成(命令)对象,从而可将用户不同的请求进行参数化.对这些请求排序或记录请求日志.以及支持回滚恢复操作.记得以前刚开始使用Photoshop时,就发现它的操作历史记录面板特别 ...
- recovery编译汉化源码开源地址
本Recovery基于xiaolu开源的不完全汉化版源码,进行完全汉化,并合并Philz的最新源码. 汉化耗费我将近一整天的精力,纯手打,可能有遗漏或翻译不准的地方,请到微博反馈 本Rec完全开源,便 ...
- Matlab 矩阵运算
1.Syms 和sym的区别: syms是定义多个符号是符号变量的意思 sym只能定义一个符号变量,但可以具体到这个符号变量的内容 例:syms f z; %定义下x和y f=sym('a+b+c') ...