SG 函数初步 HDU 1536 && HDU 1944
题目链接:http://acm.hdu.edu.cn/showproblem.php?
pid=1944
pid=1536">
http://acm.hdu.edu.cn/showproblem.php?pid=1536
给定每一次能够取的石头数,给定非常多种情况,每一种情况有若干堆石头,推断先手胜负。
SG函数打表,然后直接抑或。推断结果是否为0。第一次写SG函数,贴个代码,慢慢理解。
代码:
/* ***********************************************
Author :rabbit
Created Time :2014/7/4 12:00:18
File Name :3.cpp
************************************************ */
#pragma comment(linker, "/STACK:102400000,102400000")
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <stdlib.h>
#include <string.h>
#include <limits.h>
#include <string>
#include <time.h>
#include <math.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
using namespace std;
#define INF 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
typedef long long ll;
int f[110],d[20010],g[110];
int SG(int p,int k){
memset(g,0,sizeof(g));
for(int i=0;i<k;i++){
int t=p-f[i];
if(t<0)break;
if(d[t]==-1)d[t]=SG(t,k);
g[d[t]]=1;
}
for(int i=0;;i++)
if(!g[i])return i;
}
int main()
{
//freopen("data.in","r",stdin);
//freopen("data.out","w",stdout);
int n;
while(~scanf("%d",&n)){
if(!n)break;
for(int i=0;i<n;i++)scanf("%d",&f[i]);
sort(f,f+n);
memset(d,-1,sizeof(d));
d[0]=0;
for(int i=1;i<=10010;i++)
d[i]=SG(i,n);
int m;
scanf("%d",&m);
while(m--){
int k;
scanf("%d",&k);
int sum=0,v;
while(k--){
scanf("%d",&v);
sum^=d[v];
}
if(!sum)printf("L");
else printf("W");
}
puts("");
}
return 0;
}
SG 函数初步 HDU 1536 && HDU 1944的更多相关文章
- (巴什博弈 sg函数入门1) Brave Game -- hdu -- 1846
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1846 首先来玩个游戏,引用杭电课件上的: (1) 玩家:2人:(2) 道具:23张扑克牌:(3) 规则: ...
- hdu 3032 Nim or not Nim? sg函数 难度:0
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- HDU 1536 sg函数
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submi ...
- hdu 1536 SG函数模板题
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU 1536 S-Nim (组合游戏+SG函数)
题意:针对Nim博弈,给定上一个集合,然后下面有 m 个询问,每个询问有 x 堆石子 ,问你每次只能从某一个堆中取出 y 个石子,并且这个 y 必须属于给定的集合,问你先手胜还是负. 析:一个很简单的 ...
- hdu 2147 SG函数打表(手写也可以) 找规律
kiki's game Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 40000/1000 K (Java/Others) Total ...
- hdu 1848 简单SG函数
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1848 Problem Description 任何一个大学生对菲波那契数列(Fibonacci num ...
- HDU 5724 Chess(SG函数+状态压缩)
http://acm.split.hdu.edu.cn/showproblem.php?pid=5724 题意: 现在有一个n*20的棋盘,上面有一些棋子,双方每次可以选择一个棋子把它移动到其右边第一 ...
随机推荐
- verilog语法实例学习(4)
Verilog模块 Verilog中代码描述的电路叫模块,模块具有以下的结构: module module_name[ (portname {, portname})]; //端口列表 [parame ...
- QT国际化(中英转换)
转载:https://blog.csdn.net/u012528526/article/details/54707233 QT国际化(中英转换) 我们都知道在安卓中,想做国际化很简单,只需要建立对应的 ...
- andengine的convertLocalCoordinatesToSceneCoordinates方法
使用Tile地图,看过andengine中的例子,都会发现例子中有这么一段话,以前版本的是convertLocalToSceneCoordinates方法. scene.registerUpdateH ...
- SharePoint2013 以其他用户登录和修改AD域用户密码 功能
sharepoint默认是没有修改AD密码 和切换 用户的功能,这里我用future的方式来实现. 部署wsp前: 部署后: 点击以其他用户身份登录 点击修改用户密码: 这里的扩展才菜单我们用Cust ...
- 如何统计NFS的client在一段时间内收到了多少个字节?
可使用的命令如下: nfsstat –c nfsiostat 参考资料 ============= https://www.systutorials.com/docs/linux/man/8-nfss ...
- [Python爬虫] :Selenium +phantomjs 利用 pyquery抓取脚本链接对应的内容
抓取上面对应链接的网页的文章的内容 ele = element.attr("onclick") self.driver.execute_script(ele) sub_seleni ...
- nodejs发送请求
const https = require('https'); var options = { hostname: 'registry.yarnpkg.com', port: 443, path: ' ...
- PHP Manager for IIS
SOAP error on IIS8 Registering new PHP version sets bad values set for FastCGI activityTimeout, requ ...
- linux 查找文件或者服务
[root@localhost ~]# whereis mysql mysql: /usr/bin/mysql /usr/lib/mysql /usr/share/mysql /usr/share/m ...
- Spring3自定义环境配置 <beans profile="">
Spring 3.1的功能,以后就不用为了区分Test, Dev, Production环境,搞几个只有细微区别的application.xml, application-test.xml及引用它们的 ...