1669:S-Nim

【输入样例】

2 2 5
3
2 5 12
3 2 4 7
4 2 3 7 12
5 1 2 3 4 5
3
2 5 12
3 2 4 7
4 2 3 7 12
0

【输出样例】

LWW
WWL

【提示】

数据范围与提示:

对于全部数据,0<n,m,k≤100,0<si,ai≤104 。

sol:模板,不解释

#include <bits/stdc++.h>
using namespace std;
typedef int ll;
inline ll read()
{
ll s=;
bool f=;
char ch=' ';
while(!isdigit(ch))
{
f|=(ch=='-'); ch=getchar();
}
while(isdigit(ch))
{
s=(s<<)+(s<<)+(ch^); ch=getchar();
}
return (f)?(-s):(s);
}
#define R(x) x=read()
inline void write(ll x)
{
if(x<)
{
putchar('-'); x=-x;
}
if(x<)
{
putchar(x+''); return;
}
write(x/);
putchar((x%)+'');
return;
}
#define W(x) write(x),putchar(' ')
#define Wl(x) write(x),putchar('\n')
const int N=,B=;
int k,S[N],m,n,a[N];
int SG[B],Mark[B];
int main()
{
int i,j;
while(true)
{
R(k);
if(!k) break;
for(i=;i<=k;i++) R(S[i]);
sort(S+,S+k+);
SG[]=;
for(i=;i<=;i++)
{
for(j=;S[j]<=i&&j<=k;j++)
{
Mark[SG[i-S[j]]]=i;
}
for(j=;;j++) if(Mark[j]!=i)
{
SG[i]=j; break;
}
}
R(m);
while(m--)
{
R(n);
int ans=;
for(i=;i<=n;i++) ans^=SG[read()];
if(ans) putchar('W');
else putchar('L');
}
putchar('\n');
}
return ;
}
/*
input
2 2 5
3
2 5 12
3 2 4 7
4 2 3 7 12
5 1 2 3 4 5
3
2 5 12
3 2 4 7
4 2 3 7 12
0
output
LWW
WWL
*/

一本通1669S-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. JAVA框架Struts2--配置讲解

    一.配置讲解: <struts> <package name="oop" namespace="/" extends="struts ...

  2. C++之C++的词法单位

    C++的字符集 ASCII码字符集是计算机中的常用字符集.它包括英文字母及阿拉伯数字等128个字符,存储一个ASCII码占用一个字节单元. 由于汉字处理的需要,又出现了汉字国标码等对应于不同语言的字符 ...

  3. Eclipse-安装Spring Tool Suit 插件

    登录http://spring.io/tools/sts/all 下载所需的Spring Tool Suit安装包 我用的是springsource-tool-suite-3.6.1.RELEASE- ...

  4. Hadoop Version History and Feature

    Versions and Features Hadoop has seen significant interest over the past few years. This has led to ...

  5. web安全入门课程笔记——SQL漏洞分析与利用

    3-1SQL语言基础 3-2ACCESS手工注入 And1=1是什么意思:进入数据库查询信息,判断是否存在注入点. Exists(select*from admin):查询语句 3-6MySQL手工注 ...

  6. Python3入门(十)——调试与测试

    一.异常处理 1.try...except...finally... 这个也就是Java里的try...cath..finally...了,直接看经典代码: try: print("开始执行 ...

  7. 20155310 《网络对抗》Exp 8 Web基础

    20155310 <网络对抗>Exp 8 Web基础 基础问题回答 (1)什么是表单 表单是一个包含表单元素的区域. 表单元素是允许用户在表单中(比如:文本域.下拉列表.单选框.复选框等等 ...

  8. 使用Fortify进行代码静态分析(系列文章)

    BUG级别:低 Code Correctness(代码正确性) 1.Class does not Implement Equals(类未能实现Equals方法) Dead Code(死亡代码) 1.U ...

  9. typedef你真的理解么?

    typedef,用最简单的话去诠释他,那么就是给类型取别名!!!  但是他并没有你想象的那么简单! 举例: typedef int size;//那么int就有一个别名叫size了,以后就可以 siz ...

  10. 蓝牙Remove Bond的流程分析

    此篇文章简单分析一下蓝牙解除配对在协议栈中的工作流程.分析的协议栈版本是Android8.0 协议栈的接口都定义在bluetooth.cc这个文件中: static int remove_bond(c ...