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 Back Home键监听
Android Back Home键监听 Back键的监听 对于Back键的监听比较容易,可以在多个系统回调处拦截,比如在activity的下列方法中都可以收到Back键按下的事件: @Overrid ...
- Java基础知识强化82:Random类概述和方法使用
1. Random类 public class Random extends Object implements Serializable: 此类的实例用于生成伪随机数流.此类使用48位种子. (1) ...
- poj 1328 贪心
/* 贪心.... 处理处每个点按照最大距离在x轴上的映射 然后我们就有了一些线段 目的是选取尽量少的点 使得每个线段内都有点出现 我们按照左端点排序 然后逐一处理 假设第一个雷达安在第一个线段的右端 ...
- id名和class名有什么区别
从概念上来说: id是先找到结构/内容,再给它定义样式: class是先定义好一种样式,再套给多个结构/内容. 从样式效果上来说: id的优先级要比class高出一个层次 html中不管有几个i ...
- Java-20个非常有用的程序片段
下面是20个非常有用的Java程序片段,希望能对你有用. 1.字符串有整型的相互转换 String a = String.valueOf(2); //integer to numeric string ...
- (转)jquery的html,text,val
.html()用为读取和修改元素的HTML标签 .text()用来读取或修改元素的纯文本内容 .val()用来读取或修改表单元素的value值. 这三个方法功能上的对比 .html(),.text() ...
- Warning: World-writable config file '/etc/my.cnf' is ignored
1. 问题描述: 重启mysql服务时出现以下信息: Warning: World-writable config file '/etc/my.cnf' is ignored 出现这种情况的原因是:m ...
- Using Notepad++ to Execute Oracle SQL
原文链接:http://www.toadworld.com/products/toad-for-oracle/b/weblog/archive/2013/08/21/using-notepad-to- ...
- Jason 分享吴霁虹教授的产品模型
产品的出现都是为了解决市场上存在的某一个”疼点“或一系列的”疼点“而出现. 疼点:是一个亟需待解决的问题,对应有相应的市场,会寻找相应的解决方案.比如:用户的小孩——>因为缺钱,所以担心小孩无法 ...
- java rmi 使用方法
server package Server; import java.rmi.Naming; import java.rmi.RMISecurityManager; import java.rmi.r ...