POJ 2960
也算是一道模板题吧,只需按照SG函数的定义求出每个值的SG,然后异或就可以了。
#include <iostream>
#include <cstdio>
#include <algorithm> using namespace std;
const int N=;
int sg[N];
bool vis[N];
int k,s[];
int p[],top;
int work(int w){
int mi=,i;
for(i=;i<=k;i++){
if(w-s[i]>=)
p[++top]=sg[w-s[i]];
}
// if(w==2)
// printf("%d\n",p[0]);
sort(p,p+top+);
for(i=;i<=top;i++){
if(p[i]==mi)
mi++;
else if(p[i]>mi)
break;
}
return mi;
}
char ans[],tot;
int main(){
int i;
while(scanf("%d",&k)!=EOF){
if(!k) break;
// memset(sg,-1,sizeof(sg));
// memset(vis,false,sizeof(vis));
sg[]=;
for(i=;i<=k;i++){
scanf("%d",&s[i]);
}
for(i=;i<=;i++){
top=-;
sg[i]=work(i);
// if(i<=12)
// printf("%d ",sg[i]);
}
// printf("\n");
int n,tmp; tot=-;
scanf("%d",&k);
for(i=;i<=k;i++){
scanf("%d",&n);
int anst=;
for(int j=;j<=n;j++){
scanf("%d",&tmp);
anst=(anst^sg[tmp]);
}
if(!anst)
ans[++tot]='L';
else ans[++tot]='W';
}
for(i=;i<=tot;i++)
printf("%c",ans[i]);
printf("\n");
}
return ;
}
POJ 2960的更多相关文章
- 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 ...
- POJ 2960 S-Nim<博弈>
链接:http://poj.org/problem?id=2960 #include<stdio.h> #include<string.h> ; ; int SG[N];//S ...
- 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 sg函数几乎是模板题. 调试代码的最大障碍仍然是手残在循环里打错变量名,是时候换个hydra产的机械臂了[超想要.jpg] #includ ...
- POJ 2960 S-Nim (sg函数)
题目链接:http://poj.org/problem?id=2960 题目大意:给定数组S,接下来给出m个游戏局面.游戏局面是一些beads堆,先给出堆数,然后是每一堆中beads的数目.游戏规则是 ...
- hdu 1536/1944 / POJ 2960 / ZOJ 3084 S-Nim 博弈论
简单的SG函数应用!!! 代码如下: #include<iostream> #include<stdio.h> #include<algorithm> #inclu ...
- poj 2960 S-Nim(SG函数)
S-Nim Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 3694 Accepted: 1936 Description ...
- poj 2960 S-Nim【SG函数】
预处理出SG函数,然后像普通nim一样做即可 #include<iostream> #include<cstdio> using namespace std; const in ...
随机推荐
- ACM_Ruin of Titanic(简单贪心)
Ruin of Titanic Time Limit: 2000/1000ms (Java/Others) Problem Description: 看完Titanic后,小G做了一个梦.梦见当泰坦尼 ...
- [转]自适应网页设计(Responsive Web Design)
本文转自:http://www.ruanyifeng.com/blog/2012/05/responsive_web_design.html 作者: 阮一峰 日期: 2012年5月 1日 随着3G的普 ...
- [ USACO 2018 OPEN ] Out of Sorts (Platinum)
\(\\\) \(Description\) 对一长为\(N\)的数列\(A\)排序,不保证数列元素互异: 数列\(A\)中\(A[1...i]\)的最大值不大于\(A[i+1-N]\)的最小值,我们 ...
- python gdal 矢量转栅格
data = gdal.Open(templateTifFileName, gdalconst.GA_ReadOnly)geo_transform = data.GetGeoTransform()x_ ...
- drupal 8——打补丁(patch)
druapl 的核心可能会有漏洞,这时就需要我们去打补丁.很多补丁都已经有人写好了,我这里讲的就是如何去打这些已经写好的补丁. 对于这个问题:drupal8 核心有bug导致了两个相同的错误提示的出现 ...
- react native 报错日常 if (_total > 0) { ~~~~~~ ^ ~ 1 error generated.
node_modules/react-native/React/Base/RCTJavaScriptLoader.mm::: error: ordered comparison between poi ...
- css学习笔记---盒模型,布局
1.外边距叠加 当一个元素出现在另一个元素上面时第一个元素的底边距与第二个元素的上边距发生叠加,元素被包含时也有可能会发生叠加(如果没有内边距和边框),如果一个空元素没有内边距和边框本身也会发生上下边 ...
- Codeforces_733C
C. Epidemic in Monstropolis time limit per test 1 second memory limit per test 256 megabytes input s ...
- 扩增子分析QIIME2-4分析实战Moving Pictures
本示例的的数据来自文章<Moving pictures of the human microbiome>,Genome Biology 2011,取样来自两个人身体四个部位五个时间点 ...
- VUE路由history模式坑记--NGINX
因微信分享和自动登录需要,对于URL中存在'#'的地址,处理起来比较坑(需要手动写一些代码来处理).还有可能会有一些隐藏的问题没被发现. 如果VUE能像其他(JSP/PHP)系统的路径一样,就不存在这 ...