题意:给定n堆石子,两人轮流操作,每次选一堆石子,取任意石子或则将石子分成两个更小的堆(非0),取得最后一个石子的为胜。

题解:比较裸的SG定理,用sg定理打表,得到表1,2,4,3,5,6,8,7,9,10,12,11...可以发现当x%4==0时sg[x]=x-1;当x%4==3时sg[x]=x+1;其余sg[x]=x。然后异或下就出来结果了。

打表:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e4+;
int sg[maxn],vis[maxn];
void solve()
{
int i,j,k;
sg[]=,sg[]=;
for(i=;i<=;i++)
{
memset(vis,,sizeof(vis));
for(j=;j<i;j++)
vis[sg[j]^sg[i-j]]=; //拆分
for(j=;j<i;j++)
vis[sg[j]]=; //取石子
for(j=;;j++)
if(!vis[j])break;
sg[i]=j;
}
for(i=;i<=;i++)
cout<<sg[i]<<endl;
}
int main()
{
solve();
}

AC:

#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
const int maxn=1e6+;
int find(int x)
{
if(x%==)return x-;
else if(x%==)return x+;
return x;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int a,n,i,j,ans=;
scanf("%d",&n);
for(i=;i<n;i++)
{
scanf("%d",&a);
ans=ans^find(a);
}
if(ans==)printf("Bob\n");
else printf("Alice\n");
}
return ;
}

Nim or not Nim? HDU - 3032的更多相关文章

  1. hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)

    Nim or not Nim? Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Sub ...

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

  3. HDU 3032 Nim or not Nim? (sg函数求解)

    Nim or not Nim? Problem Description Nim is a two-player mathematic game of strategy in which players ...

  4. HDU 3032 Nim or not Nim? (sg函数)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  5. HDU 3032 Nim or not Nim?(博弈,SG打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  6. HDU 3032 Nim or not Nim?(Multi_SG,打表找规律)

    Nim or not Nim? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)T ...

  7. HDU 5795 A Simple Nim(简单Nim)

    p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...

  8. HDU 3032 multi-sg 打表找规律

    普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...

  9. 【HDU3032】Nim or not Nim?(博弈论)

    [HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...

  10. NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结

    NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结 经典NIM游戏: 一共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子 ...

随机推荐

  1. 编译openwrt时报错:FMCGenericError.h:34:27: fatal error: libxml/parser.h: No such file or directory

    解决办法: 更新openwrt的feeds,并重新make menuconfig ./script/feeds update -a ./script/feeds install -a

  2. tp框架中的一些疑点知识-7

    mysqli是用面向对象的,所以用箭头对象语法, 而mysql是用C语言面向过程写的, 所以用的都是php全局函数 式的写法. tinkle: 叮叮当当的响; (口语)一次电话, i will giv ...

  3. NodeJs 在window中安装使用

    Nodejs: 官网下载长期版本zip格式解压 D:\Program Files\nodejs 查看版本 D:\Git\SpringBootDemo (master) $ node -v v8.11. ...

  4. 论文阅读之: Hierarchical Object Detection with Deep Reinforcement Learning

    Hierarchical Object Detection with Deep Reinforcement Learning NIPS 2016 WorkShop  Paper : https://a ...

  5. iframe初始化属性

    <iframe id="user" src="xxx.html" frameborder="0" width="" ...

  6. 【C#】神奇的yeild

    直接出栗子: class Program { static void Main(string[] args) { foreach (var item in FilterWithoutYield) { ...

  7. JAVA 上传文件到linux上并解压缩

    package com.inborn.inshop.controller.mkt; import java.io.*; import ch.ethz.ssh2.ChannelCondition;imp ...

  8. SAP本地化-银企直连

    SAP本地化-银企直连 http://blog.sina.com.cn/s/blog_a0de8cc80101dee1.html 一.发展历史 2011年,在SAP ECC6 Ehp5中,通过功能增强 ...

  9. hihoCoder 1116 计算(线段树)

    http://hihocoder.com/problemset/problem/1116 题意: 思路: 用线段树解决,每个节点需要设置4个变量,sum记录答案,all记录整个区间的乘积,pre记录该 ...

  10. 1.Jenkins 在windows下的安装与配置

    1. 安装Jenkins 1.war包安装:启动Jenkins命令,打开cmd至Jenkins安装目录下,运行命令 java -jar jenkins.war 如果改变默认端口,则指定端口例如端口号1 ...