硬币游戏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)的更多相关文章

  1. hdu5795 A Simple Nim 求nim求法,打表找sg值规律 给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作可以选择任意一堆取走任意个石子(不可以为空) 或者选择一堆,把它分成三堆,每堆不为空。求先手必胜,还是后手必胜。

    /** 题目:A Simple Nim 链接:http://acm.hdu.edu.cn/showproblem.php?pid=5795 题意:给定n堆石子,每堆有若干石子,两个人轮流操作,每次操作 ...

  2. hdu1356&hdu1944 博弈论的SG值(王道)

    S-NimProblem DescriptionArthur and his sister Caroll have been playing a game called Nim for some ti ...

  3. 【UVA1378】A Funny Stone Game (博弈-求SG值-输出方案)

    [题目] Description The funny stone game is coming. There are n piles of stones, numbered with 0, 1, 2, ...

  4. 题解报告:hdu 1847 Good Luck in CET-4 Everybody!(入门SG值)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1847 Problem Description 大学英语四级考试就要来临了,你是不是在紧张的复习?也许紧 ...

  5. 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 ...

  6. hdu 1536 S-Nim_求sg值模版

    题意:给你很n堆石头,k代表你有k种拿法,然后给出没堆石头的数量,求胜负 直接套用模版 找了好久之前写的代码贴上来 #include<iostream> #include<algor ...

  7. Treblecross 博弈SG值

    Treblecross is a two player game where the goal is to get three X in a row on a one-dimensional boar ...

  8. Nim 游戏、SG 函数、游戏的和

    Nim游戏 Nim游戏定义 Nim游戏是组合游戏(Combinatorial Games)的一种,准确来说,属于“Impartial Combinatorial Games”(以下简称ICG).满足以 ...

  9. 博弈论之Nim

    博弈论(一):Nim游戏 重点结论:对于一个Nim游戏的局面(a1,a2,...,an),它是P-position当且仅当a1^a2^...^an=0,其中^表示位异或(xor)运算. Nim游戏是博 ...

随机推荐

  1. IIS7配置PHP简要说明

    1. IIS7 安装的时候 要注意三个地方打得勾 万维网服务->应用程序开发功能->CGI ->ISAPI扩展 ->ISAPI筛选器 注:   CGI  会在IIS7+PHP_ ...

  2. Kestrel Web 服务器学习笔记

    前言: ASP.NET Core 已经不是啥新鲜的东西,很多新启的项目都会首选 Core 做开发: 而 Kestrel 可以说是微软推出的唯一真正实现跨平台的 Web 服务器了: Kestrel 利用 ...

  3. 八大排序算法原理以及Java实现(直接插入排序)

    概述 排序有内部排序和外部排序,内部排序是数据记录在内存中进行排序,而外部排序是因排序的数据很大,一次不能容纳全部的排序记录,在排序过程中需要访问外存. 我们这里说说八大排序就是内部排序. 当n较大, ...

  4. BEC listen and translation exercise 13

    The old lady sits on a mobile chair every morning. He got a large fortune when his father died, but ...

  5. Linux 线程同步的三种方法(互斥锁、条件变量、信号量)

    互斥锁 #include <cstdio> #include <cstdlib> #include <unistd.h> #include <pthread. ...

  6. NSString *const 和 const NSString * 的区别

    1.变量存储的指针可变,变量存储的值不可变 //A modifiable pointer to a constant NSString (its value can't be modified) &q ...

  7. 仿百度下拉关键词,和关键词的小demo

    自己做项目时用到的仿百度下拉关键词 代码: $(function(){ var oTxt = document.getElementById('search_text'); oTxt.onkeyup ...

  8. BZOJ2141:排队

    浅谈分块:https://www.cnblogs.com/AKMer/p/10369816.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php?i ...

  9. BZOJ4195:[NOI2015]程序自动分析

    浅谈并查集:https://www.cnblogs.com/AKMer/p/10360090.html 题目传送门:https://lydsy.com/JudgeOnline/problem.php? ...

  10. CentOS 7 安装Percona,Xtrabackup

    CentOS 7 安装Percona 5.7,Xtrabackup 简介 Percona Server为 MySQL 数据库服务器进行了改进,在功能和性能上较 MySQL 有着很显著的提升.该版本提升 ...