Day11 - M - Nim or not Nim? HDU - 3032
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的更多相关文章
- hdu 3032 Nim or not Nim? (SG函数博弈+打表找规律)
Nim or not Nim? Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Sub ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- 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 ...
- HDU 5795 A Simple Nim(简单Nim)
p.MsoNormal { margin: 0pt; margin-bottom: .0001pt; text-align: justify; font-family: Calibri; font-s ...
- HDU 3032 multi-sg 打表找规律
普通NIM规则加上一条可以分解为两堆,标准的Multi-SG游戏 一般Multi-SG就是根据拓扑图计算SG函数,这题打表后还能发现规律 sg(1)=1 sg(2)=2 sg(3)=mex{0,1,2 ...
- 【HDU3032】Nim or not Nim?(博弈论)
[HDU3032]Nim or not Nim?(博弈论) 题面 HDU 题解 \(Multi-SG\)模板题 #include<iostream> #include<cstdio& ...
- NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结
NIM游戏,NIM游戏变形,威佐夫博弈以及巴什博奕总结 经典NIM游戏: 一共有N堆石子,编号1..n,第i堆中有个a[i]个石子. 每一次操作Alice和Bob可以从任意一堆石子中取出任意数量的石子 ...
随机推荐
- html学习-第一集(基本标签)
什么是HTML html是一套规则,浏览器认识的规则 开发者怎么使用html 学习HTML语言 开发后台程序 写HTML文件 从数据库获取数据,然后替换到html中对应的位子(web框架) HTML文 ...
- django模块导入/函数/中间件/MVC和MTV/CSRF
目录 一:模块导入 二:函数 三:中间件 四:MVC和MTV 五:csrf 一:模块导入 第一种:继承 这里的母版更像是一个架子,子板都是定义的内容(如果多个页面中 ,存在相同的页面:这样我们可以抽到 ...
- [Bug合集] java.lang.IllegalStateException: Could not find method onClickcrea(View) in a parent
出现场景: 在一个Button中定义了onclick属性,值为startChat. 在Activity中定义一个方法. public void startChat(View view){} 运行时,点 ...
- How to Start Learning Computer Graphics
Background Input\Output Image Knowledge Image Digital Image Processing Computer Vision Knowledge Com ...
- laravel 报错The Mix manifest does not exist.
这是因为我们在 resources/views/layouts/app.blade.php 中使用 mix() 方法,而我们还未运行 Laravel Mix 进行编译,找不到 mix-manifest ...
- L3-023 计算图
建立结构体保存每个结点的前驱,操作符,来回两遍拓扑排序~ #include<bits/stdc++.h> using namespace std; ; struct node { vect ...
- 搭建一个ssm框架的maven项目需要配置的文件
单独功能需要的配置文件: 1,mybatis配置文件 mybatis-config.xml2,spring配置文件 spring-context.xml ......3,we ...
- springMVC的跳转
服务器内部跳转: return "forward:/forward/test1"; 或者 request.getRequestDispatcher(path).forward(r ...
- Install fail! Error: EBUSY: resource busy or locked, symlink
前些日子从github上下载了一个项目 然后放在桌面上 ,但是运行的时候 报了Install fail! Error: EBUSY: resource busy or locked, symlink ...
- ROM, RAM, NVRAM and Flash Memory on Cisco Routers
当谈到路由器有多少内存以及哪些内存做什么时,有时人们会感到困惑. 您应该熟悉4个内存术语,在升级路由器的IOS之前应检查其中2个. 这些是以下内容: ROM:ROM代表只读存储器. 它存储System ...