一本通1669S-Nim
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的更多相关文章
- [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 ...
随机推荐
- P3195 [HNOI2008]玩具装箱TOY
列出DP方程式:设f[i]表示分组完前i件物品的最小花费,为方便计算,设sum[i]表示是前i件物品的长度和. f[i]=min(f[j]+(sum[i]-sum[j]+i-j-L-1)^2) [0& ...
- day 27
今日内容: 关于面向对象的一些内置方法 1.__str__:在对象被打印时自动触发,可用来定义对象被打印. 注意:返回必须是一个字符串类型的值 ############################ ...
- lucas定理的证明
http://baike.baidu.com/link?url=jJgkOWPSRMobN7Zk4kIrQAri8m0APxcxP9d-C6qSkIuembQekeRwUoEoBd6bwdidmoCR ...
- 详解如何使用Docker Hub官方的MySQL镜像生成容器
一直在尝试以官方CentOS镜像为基础,制作基于CentOS的MySQL镜像.但是制作后发现镜像大小已经超过1.5G,这对于一般的Docker镜像来说太臃肿了.Docker Hub官方提供的CentO ...
- 【本地服务器】用nginx进行反向代理处理(windows)
在通过json-server搭建本地服务器得到 http://localhost:3000/todos 的基础上,要想将接口改为www.test.com/todos这样的形式 ,则需要用nginx ...
- 20155330 《网络对抗》 Exp6 信息搜集与漏洞扫描
20155330 <网络对抗> Exp6 信息搜集与漏洞扫描 基础问题回答 哪些组织负责DNS,IP的管理? 互联网名称与数字地址分配机构(The Internet Corporation ...
- Hadoop日记Day9---HDFS的java访问接口
一.搭建Hadoop 开发环境 我们在工作中写完的各种代码是在服务器中运行的,HDFS 的操作代码也不例外.在开发阶段,我们使用windows 下的eclipse 作为开发环境,访问运行在虚拟机中的H ...
- Redis学习之路(四)之Redis集群
[toc] #Redis集群 1.Redis Cluster简介 Redis Cluster为Redis官方提供的一种分布式集群解决方案.它支持在线节点增加和减少. 集群中的节点角色可能是主,也可能是 ...
- effective c++ 笔记 (13-17)
//---------------------------15/03/30---------------------------- //#13 以对象管理资源 { void f() { Inves ...
- LeetCode Container With Most Water (Two Pointers)
题意 Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai ...