Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come from the same heap.

Nim is usually played as a misere game, in which the player to take the last object loses. Nim can also be played as a normal play game, which means that the person who makes the last move (i.e., who takes the last object) wins. This is called normal play because most games follow this convention, even though Nim usually does not.

Alice and Bob is tired of playing Nim under the standard rule, so they make a difference by also allowing the player to separate one of the heaps into two smaller ones. That is, each turn the player may either remove any number of objects from a heap or separate a heap into two smaller ones, and the one who takes the last object wins.

InputInput contains multiple test cases. The first line is an integer 1 ≤ T ≤ 100, the number of test cases. Each case begins with an integer N, indicating the number of the heaps, the next line contains N integers s[0], s[1], ...., s[N-1], representing heaps with s[0], s[1], ..., s[N-1] objects respectively.(1 ≤ N ≤ 10^6, 1 ≤ S[i] ≤ 2^31 - 1)OutputFor each test case, output a line which contains either "Alice" or "Bob", which is the winner of this game. Alice will play first. You may asume they never make mistakes.Sample Input

2
3
2 2 3
2
3 3

Sample Output

Alice
Bob 思路:Multi-SG问题,我们打表找规律,然后用SG函数即可
#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; const int maxm = ; int sg[maxm];
bool vis[maxm]; void run_case() {
sg[] = ;
for(int i = ; i < maxm; ++i) {
memset(vis, , sizeof(vis));
for(int j = ; j <= i; ++j) {
vis[sg[j]] = true;
if(j != i && j != ) vis[sg[j]^sg[i-j]] = true;
} for(int j = ;;++j) {
if(!vis[j]) {
sg[i]=j;
break;
}
}
}
for(int i = ; i < maxm; ++i)
cout << i << " " << sg[i] << "\n";
} int main() {
ios::sync_with_stdio(false), cin.tie();
//int t; cin >> t;
//while(t--)
run_case();
cout.flush();
return ;
}

打表

打表后可以发现规律,每4个一个轮回,1234 就是1243 5678就是5687 规律很显然

#include<bits/stdc++.h>
using namespace std;
#define lowbit(x) ((x)&(-x))
typedef long long LL; int getsg(int x) {
if(x% == ) return x-;
else if(x% == ) return x+;
return x;
} void run_case() {
int n, ans = , val;
cin >> n;
while(n--) {
cin >> val;
ans ^= getsg(val);
}
if(!ans) cout << "Bob\n";
else cout << "Alice\n";
} int main() {
ios::sync_with_stdio(false), cin.tie();
int t; cin >> t;
while(t--)
run_case();
cout.flush();
return ;
}
												

Day11 - M - 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. [Linux kali] Kali KDE桌面安装中文输入法 不能登录系统

    #开始 第一次实体机上面安装kali的KDE桌面版本 结果就遇到了很多的BUG 比如这次就是安装中文输入法有问题 这次安装的是fcitx框架的 尝试了 谷歌输入法 还有搜狗输入法 都有这个问题 也就是 ...

  2. 吴裕雄 python 神经网络——TensorFlow 三层简单神经网络的前向传播算法

    import tensorflow as tf w1= tf.Variable(tf.random_normal([2, 3], stddev=1, seed=1)) w2= tf.Variable( ...

  3. go get下载包失败问题

    文章引用自 解决go get下载包失败问题 从github克隆 golang在github上建立了一个镜像库,如https://github.com/golang/net就对应是 https://go ...

  4. Go语言基础之os

    文章引用自 package os import "os" os包提供了操作系统函数的不依赖平台的接口.设计为Unix风格的,虽然错误处理是go风格的:失败的调用会返回错误值而非错误 ...

  5. 2020牛客寒假算法基础集训营3 - G. 牛牛的Link Power II(线段树)

    题目链接:牛牛的Link Power II 题意:给你一个只含$0$和$1$的串,定义串的$Link$值为串中两个的$1$之间的距离的和,$(u,v)$和$(v,u)$被看认为是同一对,有$m$次操作 ...

  6. 淘淘商城之httpclient

    一.什么是httpclient HTTP 协议可能是现在 Internet 上使用得最多.最重要的协议了,越来越多的 Java 应用程序需要直接通过 HTTP 协议 来访问网络资源:虽然在 JDK 的 ...

  7. XMPP详解

    https://www.jianshu.com/p/84d15683b61e https://www.cnblogs.com/lurenq/p/7026983.html 1. xmpp简介 XMPP ...

  8. django 中url与path小记

    1. 在django 2.0中增加了一些新的特性 更简单的URL路由语法 (Simplified URL routing syntax) admin应用的针对移动设备的优化改进(Mobile-frie ...

  9. ubuntu 18 python3.6更换国内源和pip3源

    1.更换国内源 查看Ubuntu18版本和codename(一定要注意codename对应) lsb_release -a No LSB modules are available. Distribu ...

  10. Spring Boot FreeMarker 使用教程

    FreeMarker 跟 Thymeleaf 一样,是一种模板引擎,他可以无缝兼容 FreeMarker 在 Spring Boot 开发者中仍然有着很高的地位. 本章重点内容 编写一个最简单的 Fr ...