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 ...
随机推荐
- 使用Donut Caching和Donut Hole Caching在ASP.NET MVC应用中缓存页面
Donut Caching是缓存除了部分内容以外的整个页面的最好的方式,在它出现之前,我们使用"输出缓存"来缓存整个页面. 何时使用Donut Caching 假设你有一个应用程序 ...
- 【翻译习作】 Windows Workflow Foundation程序开发-第一章05
1.3 开发我们的第一个工作流 也许你曾经在这样的产品经理手下搞过开发:他总是在你身边转悠,并不时的问一句“你还没做完吗?”.在这一部分,我们将用一个简单的Windows Workflow程 ...
- Type-base dispatch
In the previous section we added two Time objects, but you also might want to add an integer to a Ti ...
- hive安装(一)
1.解压 [root@cluster3 hadoop]# tar -zxvf apache-hive--bin.tar.gz 2.修改环境变量 export HIVE_HOME=/usr/local/ ...
- 如何在后台动态生成ASPxCheckBoxList标签并循环(数据调用存储过程)
DataTable dt_attrname = new DataTable(); DataTable dt_valuename = new DataTable(); dt_valuename = go ...
- Collection集合之六大接口(Collection、Set、List、Map、Iterator和Comparable)
首先,我们先看一下Collection集合的基本结构: 1.Collection接口 Collection是最基本集合接口,它定义了一组允许重复的对象.Collection接口派生了两个子接口Set和 ...
- js中的条件语句
//js中的条件语句 ; //example1 单分支语句 ){ console.log("你已经不年轻了!"); }else{ console.log("你依然很有活力 ...
- React模板
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 让chrome打开手机网页
在chrome快捷方式上点右键: "C:\Program Files\Google\Chrome\Application\chrome.exe" -user-agent=" ...
- Android开发教程AnimationDrawable逐帧播放动画
下面我们一起来看篇Android开发AnimationDrawable控制逐帧播放动画实现过程,希望文章对各位朋友带不一些帮助. 当我们点击按钮时,该图片会不停的旋转,当再次点击按钮时,会停止在当前的 ...