POJ 2960 S-Nim<博弈>
链接:http://poj.org/problem?id=2960
#include<stdio.h>
#include<string.h>
const int N = ;
const int M= ;
int SG[N];//SG[i]记录一堆i颗石子的SG状态
int s[M];//存储可选取的石子数目集合
int k;//s[]集合中的元素个数
int mex(int x)
{
if( SG[x]!=- )return SG[x];
bool vi[N]={};
for( int i=; i<k; ++ i ){
if( s[i] <= x ){
vi[mex(x-s[i])]=;
}
}
int i=;
while(vi[i])++i;
return SG[x]=i;
}
int main()
{
while(scanf("%d",&k)!=EOF)//可选集合中的元素个数
{
if(k==)break;
int i,ans;
for(i=; i<k; i++)
scanf("%d",&s[i]);
memset(SG,-,sizeof(SG));
SG[]=;
int m;
scanf("%d",&m);//测试组数
while(m--)
{
ans=;
int l;
scanf("%d",&l);//石子堆数
while(l--)
{
int x;
scanf("%d",&x);//当前堆石子数目
if(SG[x]==-)
SG[x]=mex(x);
ans=ans^SG[x];
} if(ans==)printf("L");
else
printf("W");
} printf("\n");
} return ;
}
POJ 2960 S-Nim<博弈>的更多相关文章
- poj 2960 S-Nim
S-Nim Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4113 Accepted: 2158 Description ...
- HDU3544 Alice's Game && POJ 2960 S-Nim(SG函数)
题意: 有一块xi*Yi的矩形巧克力,Alice只允许垂直分割巧克力,Bob只允许水平分割巧克力.具体来说,对于Alice,一块巧克力X i * Y i,只能分解成a * Y i和b * Y i其中a ...
- S-Nim POJ - 2960 Nim + SG函数
Code: #include<cstdio> #include<algorithm> #include<string> #include<cstring> ...
- POJ 2960 博弈论
题目链接: http://poj.org/problem?id=2960 S-Nim Time Limit: 2000MS Memory Limit: 65536K 问题描述 Arthur and h ...
- POJ 2960 S-Nim (sg函数)
题目链接:http://poj.org/problem?id=2960 题目大意:给定数组S,接下来给出m个游戏局面.游戏局面是一些beads堆,先给出堆数,然后是每一堆中beads的数目.游戏规则是 ...
- POJ 2960 S-Nim 博弈论 sg函数
http://poj.org/problem?id=2960 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...
- poj 2960 S-Nim(SG函数)
S-Nim Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3694 Accepted: 1936 Description ...
- Georgia and Bob POJ - 1704 阶梯Nim
$ \color{#0066ff}{ 题目描述 }$ Georgia and Bob decide to play a self-invented game. They draw a row of g ...
- poj 2960 S-Nim【SG函数】
预处理出SG函数,然后像普通nim一样做即可 #include<iostream> #include<cstdio> using namespace std; const in ...
随机推荐
- Unity WebSocket(仅适用于WebGL平台)
!!!转载注明:http://www.cnblogs.com/yinlong1991/p/unity_ylwebsocket.html Unity WebSocket 使用 1.下载 YLWebSoc ...
- css+js+html基础知识总结
css+js+html基础知识总结 一.CSS相关 1.css的盒子模型:IE盒子模型.标准W3C盒子模型: 2.CSS优先级机制: 选择器的优先权:!important>style(内联样式) ...
- [UI]Flat UI - Free Boorstrap Framework and Theme
---------------------------------------------------------------------------------------------------- ...
- dumpsys命令的使用及telephony.registry解读
adb shell dumpsys,默认打印出当前系统所有的service信息,通常情况下我们并不想看那么多信息,可以在后面加上具体的服务名,比如想获取关于设备电池的信息,就可以使用以下命令: > ...
- 移动端拖拽(模块化开发,触摸事件,webpack)
通过jquery可以很容易实现CP端的拖拽.但是在移动端却不好用了.于是我自己写了一个在移动端的拖拽demo,主要用到的事件是触摸事件(touchstart,touchmove和touchend). ...
- 尝试自己建立以alpine 为基础的docker基础镜像和组件镜像
安装ubuntu14.04 然后 #获取root权限 sudo su #安装docker apt-get install docker #准备基础镜像 docker pull alpine docke ...
- VS2010 C++ 操作Excel表格的编程实现
转载请注明原文网址: http://www.cnblogs.com/xianyunhe/archive/2011/09/25/2190485.html 通过VC实现对Excel表格的操作的方法有多种, ...
- TP-Link访问策略
参考资料: http://service.tp-link.com.cn/detail_article_111.html
- hdu1864
use the cnt as the limit. #include <string.h> #include <stdio.h> ],sum; ]; double a,b,c; ...
- Mybatis多条件查询
在Mybatis多条件查询中: 1.参数如果是多条件,则需要将将添加到Map集合中进行传入. 2.就是将其参数用有序数字进行代替. Mybatis单个String类型参数传递 mysql文如下,传入参 ...