HDU 1536 sg-NIM博弈类
题意:每次可以选择n种操作,玩m次,问谁必胜。c堆,每堆数量告诉。
题意:sg—NIM系列博弈模板题
把每堆看成一个点,求该点的sg值,异或每堆sg值。
将多维转化成一维,性质与原始NIM博弈一样。
- // #pragma comment(linker, "/STACK:1024000000,1024000000")
- #include <iostream>
- #include <cstdio>
- #include <cstring>
- #include <sstream>
- #include <string>
- #include <algorithm>
- #include <list>
- #include <map>
- #include <vector>
- #include <queue>
- #include <stack>
- #include <cmath>
- #include <cstdlib>
- // #include <conio.h>
- using namespace std;
- #define clc(a,b) memset(a,b,sizeof(a))
- #define inf 0x3f3f3f3f
- #define lson l,mid,rt<<1
- #define rson mid+1,r,rt<<1|1
- const int N = ;
- const int MOD = 1e9+;
- #define LL long long
- #define mi() (l+r)>>1
- double const pi = acos(-);
- void fre() {
- freopen("in.txt","r",stdin);
- }
- // inline int r() {
- // int x=0,f=1;char ch=getchar();
- // while(ch>'9'||ch<'0') {if(ch=='-') f=-1;ch=getchar();}
- // while(ch>='0'&&ch<='9') { x=x*10+ch-'0';ch=getchar();}return x*f;
- // }
- int n,m;
- int a[N];
- int sg[N];
- int mex(int x){
- int g[];
- clc(g,);
- for(int i=;i<n;i++){
- int res=x-a[i];
- if(res<) break;
- if(sg[res]==-)
- sg[res]=mex(res);
- g[sg[res]]=;
- }
- for(int i=;i<;i++){
- if(!g[i])
- return i;
- }
- }
- int main(){
- // fre();
- while(~scanf("%d",&n),n){
- // clc(g,0);
- clc(sg,-);
- sg[]=;
- for(int i=;i<n;i++)
- scanf("%d",&a[i]);
- sort(a,a+n);
- scanf("%d",&m);
- while(m--){
- int c;
- int s=;
- scanf("%d",&c);
- while(c--){
- int x;
- scanf("%d",&x);
- if(sg[x]==-)
- sg[x]=mex(x);
- // cout<<sg[x]<<endl;
- // system("pasuse");
- s^=sg[x];
- }
- // cout<<s<<endl;
- if(s==)
- printf("L");
- else
- printf("W");
- }
- printf("\n");
- }
- return ;
- }
HDU 1536 sg-NIM博弈类的更多相关文章
- hdu 1536 sg (dfs实现)
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 Submi ...
- hdu 1536 SG函数模板题
S-Nim Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Subm ...
- HDU 1848 SG函数博弈
Fibonacci again and again Problem Description 任何一个大学生对菲波那契数列(Fibonacci numbers)应该都不会陌生,它是这样定义的:F(1 ...
- HDU 1907 John nim博弈变形
John Problem Description Little John is playing very funny game with his younger brother. There is ...
- S-Nim HDU 1536 博弈 sg函数
S-Nim HDU 1536 博弈 sg函数 题意 首先输入K,表示一个集合的大小,之后输入集合,表示对于这对石子只能去这个集合中的元素的个数,之后输入 一个m表示接下来对于这个集合要进行m次询问,之 ...
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- HDU 2509 Nim博弈变形
1.HDU 2509 2.题意:n堆苹果,两个人轮流,每次从一堆中取连续的多个,至少取一个,最后取光者败. 3.总结:Nim博弈的变形,还是不知道怎么分析,,,,看了大牛的博客. 传送门 首先给出结 ...
- hdu 1730 Nim博弈
题目来源:http://acm.hdu.edu.cn/showproblem.php?pid=1730 Nim博弈为:n堆石子,每个人可以在任意一堆中取任意数量的石子 n个数异或值为0就后手赢,否则先 ...
随机推荐
- s3cmd的安装与使用
s3cmd 是一款 Amazon S3 命令行工具.它不仅能上传.下载.同步,还能设置权限,下面是完整的安装使用指南. 主要是还是用来储存日志文件或者其他什么资料. https://wangyan. ...
- ios开发--高德地图SDK使用简介
高德LBS开放平台将高德最专业的定位.地图.搜索.导航等能力,以API.SDK等形式向广大开发者免费开放.本章节我们来简单学习一下如何使用它的定位及地图SDK. 一.相关框架及环境配置 地图SDK 对 ...
- Orcle数据库查询练习复习:二
一.题目 1.找出所有成绩均低于80的学生姓名 select sname from student where sid in( ) select sname from student where si ...
- UDP丢包和无序 问题的解决方法
最近在做一个项目,在这之前,做了个验证程序. 发现客户端连续发来1000个1024字节的包,服务器端出现了丢包现象. 纠其原因,是服务端在还未完全处理掉数据,客户端已经数据发送完毕且关闭了. 我用过s ...
- cdev_init函数
linux-2.6.22/include/linux/cdev.hstruct cdev { struct kobject kobj; // 每个 cdev 都是一个 kobje ...
- maven - setting.xml
<?xml version="1.0" encoding="UTF-8"?> <!-- Licensed to the Apache Soft ...
- LICEcap 简洁易用的动画屏幕录制软件
LICEcap 简洁易用的动画屏幕录制软件 LICEcap 捕捉屏幕的区域并保存为gif动画(便于网络发布)或lcf格式(见下). LICEcap 直观易用,功能灵活,支持 Windows 和 OSX ...
- 添加gif效果图
1.贴加第三方包 http://blog.csdn.net/iamlazybone/article/details/5972234 2. <FrameLayout android:id=&quo ...
- Android Dialog使用举例
在Android开发中,我们经常会需要在Android界面上弹出一些对话框,比如询问用户或者让用户选择.这些功能我们叫它Android Dialog对话框,在我们使用Android的过程中,我归纳了一 ...
- chrome 远程调试(转)
http://www.tuicool.com/articles/ZJfeAzi 由于 appspot.com被墙,一般调试不成功. 随着智能手机的普及,移动设备的浏览器功能越来越强大,我们用手机上网时 ...