sg值的求解(NIM)
硬币游戏2
挑战程序设计竞赛P315
1堆的情况:
#include<bits/stdc++.h>
int x=,grundy[],k=,A[]={,},n=;
using namespace std;
int main(){
grundy[]=;
for(int i=;i<=;i++){
set<int>s;
for(int j=;j<k;j++){
if(i>=A[j]) s.insert(grundy[i-A[j]]);
}
int g=;
if(s.count(g)!=) g++;
grundy[i]=g;
}
if(grundy[x]) printf("Alice\n");
else printf("Bob\n"); }
n堆的情况:
#include<bits/stdc++.h>
#define MAX_N 1000
#define MAX_K 1000
#define MAX_X 1000
using namespace std;
int N=,K=,X[MAX_N]={,,},A[MAX_K]={,,};
int grundy[MAX_X+];
int main(){
grundy[]=;
int max_x=*max_element(X,X+N); for(int i=;i<=max_x;i++){
set<int>s;
for(int j=;j<K;j++){
if(A[j]<=i) s.insert(grundy[i-A[j]]);
}
int g=;
while(s.count(g)!=) g++;
grundy[i]=g;
} int x=;
for(int i=;i<N;i++) x^=grundy[X[i]]; if(x!=) puts("Alice\n");
else puts("Bob\n");
return ;
}
sg值的求解(NIM)的更多相关文章
- hdu5795 A Simple Nim 求nim求法,打表找sg值规律 给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作可以选择任意一堆取走任意个石子(不可以为空) 或者选择一堆,把它分成三堆,每堆不为空。求先手必胜,还是后手必胜。
/** 题目:A Simple Nim 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5795 题意:给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作 ...
- hdu1356&hdu1944 博弈论的SG值(王道)
S-NimProblem DescriptionArthur and his sister Caroll have been playing a game called Nim for some ti ...
- 【UVA1378】A Funny Stone Game (博弈-求SG值-输出方案)
[题目] Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2, ...
- 题解报告:hdu 1847 Good Luck in CET-4 Everybody!(入门SG值)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1847 Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧 ...
- Nim or not Nim? hdu3032 SG值打表找规律
Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)T ...
- hdu 1536 S-Nim_求sg值模版
题意:给你很n堆石头,k代表你有k种拿法,然后给出没堆石头的数量,求胜负 直接套用模版 找了好久之前写的代码贴上来 #include<iostream> #include<algor ...
- Treblecross 博弈SG值
Treblecross is a two player game where the goal is to get three X in a row on a one-dimensional boar ...
- Nim 游戏、SG 函数、游戏的和
Nim游戏 Nim游戏定义 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG).满足以 ...
- 博弈论之Nim
博弈论(一):Nim游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算. Nim游戏是博 ...
随机推荐
- TCP/IP详解学习笔记(2)-数据链路层【转】
转自:http://blog.csdn.net/goodboy1881/article/details/665061 数据链路层有三个目的: 为IP模块发送和 接收IP数据报. 为ARP模块发送ARP ...
- Unity3D重要知识点(转)
Unity3D重要知识点 数据结构和算法很重要!图形学也很重要!大的游戏公司很看重个人基础,综合能力小公司看你实际工作能力,看你的Demo. 1.什么是渲染管道? 是指在显示器上为了显示出图像而经过的 ...
- Mysql进程管理
mysql> show processlist;+----+------+-----------+------+---------+------+-------+---------------- ...
- LeetCode OJ:Populating Next Right Pointers in Each Node II(指出每一个节点的下一个右侧节点II)
Follow up for problem "Populating Next Right Pointers in Each Node". What if the given tre ...
- 《Effective C++》——条款17:以独立语句将newed对象置入智能指针
假设有如下两个函数: int priority(); void processWidget(std::tr1::shared_ptr<Widget>pw, int priority); 对 ...
- 远程激活.NET REFLECTOR(不能断网)
由于是远程连接的服务器,使用.Net Reflector注册机激活时,不能断网. 如何禁止Reflector连接她的激活服务器,可进行如下操作: 1.添加hosts: 0.0.0.0 red-gate ...
- BZOJ4808: 马
BZOJ4808: 马 https://lydsy.com/JudgeOnline/problem.php?id=4808 分析: 黑白染色,求二分图最大匹配即可. 代码: #include < ...
- 橱窗布置(Flower)(动规)
橱窗布置(Flower) [问题描述] 假设以最美观的方式布置花店的橱窗,有F束花,每束花的品种都不一样,同时,至少有同样数量的花瓶,被按顺序摆成一行,花瓶的位置是固定的,并从左到右, ...
- 洛谷【P1048】采药
浅谈\(DP\):https://www.cnblogs.com/AKMer/p/10437525.html 题目传送门:https://www.luogu.org/problemnew/show/P ...
- zabbix监控进程
参考http://chenx1242.blog.51cto.com/10430133/1837990 1 前期说明 zabbix_server查看“文件在后台运行数量”所对应的key就是:proc.n ...