连刷3道博弈模板题,算是稍微学习了以下三个经典博弈了。推荐一个博客

第一道模板:Bash博弈——同余理论

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
有一堆石子共有N个。A B两个人轮流拿,A先拿。每次最少拿1颗,最多拿K颗,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N和K,问最后谁能赢得比赛。
例如N = 3,K = 2。无论A如何拿,B都可以拿到最后1颗石子。
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行2个数N,K。中间用空格分隔。(1 <= N,K <= 10^9)
Output
共T行,如果A获胜输出A,如果B获胜输出B。
Input示例
4
3 2
4 2
7 3
8 3
Output示例
B
A
A
B
//Asimple
#include <bits/stdc++.h>
//#define INF 0x3fffffff
#define swap(a,b,t) t = a, a = b, b = t
#define CLS(a, v) memset(a, v, sizeof(a))
#define debug(a) cout << #a << " = " << a <<endl
#define test() cout<<"=========="<<endl
using namespace std;
typedef long long ll;
const int maxn = +;
const double PI=acos(-1.0);
//const ll mod = 1000005;
const int INF = ( << ) ;
const int dx[] = {-, , , };
const int dy[] = { ,-, , };
ll n, m, res, ans, len, T, k, num, sum;
ll mod; void input() {
ios_base::sync_with_stdio(false);
cin >> T;
while( T -- ) {
cin >> n >> m;
if( n%(m+)!= ) cout << "A" << endl;
else cout << "B" << endl;
}
} int main(){
input();
return ;
}

第二道:Nim游戏——异或理论

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
有N堆石子。A B两个人轮流拿,A先拿。每次只能从一堆中取若干个,可将一堆全取走,但不可不取,拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出N及每堆石子的数量,问最后谁能赢得比赛。
例如:3堆石子,每堆1颗。A拿1颗,B拿1颗,此时还剩1堆,所以A可以拿到最后1颗石子。
 
Input
第1行:一个数N,表示有N堆石子。(1 <= N <= 1000)
第2 - N + 1行:N堆石子的数量。(1 <= A[i] <= 10^9)
Output
如果A获胜输出A,如果B获胜输出B。
Input示例
3
1
1
1
Output示例
A
//Asimple
#include <bits/stdc++.h>
//#define INF 0x3fffffff
#define swap(a,b,t) t = a, a = b, b = t
#define CLS(a, v) memset(a, v, sizeof(a))
#define debug(a) cout << #a << " = " << a <<endl
#define test() cout<<"=========="<<endl
using namespace std;
typedef long long ll;
const int maxn = +;
const double PI=acos(-1.0);
const ll mod = ;
const int INF = ( << ) ;
const int dx[] = {-, , , };
const int dy[] = { ,-, , };
ll n, m, res, ans, len, T, k, num, sum;
//ll mod; void input() {
ios_base::sync_with_stdio(false);
while( cin >> n ) {
ans = ;
for(int i=; i<n; i++) {
cin >> num;
ans ^= num;
}
if( !ans ) cout << "B" << endl;
else cout << "A" << endl;
}
} int main(){
input();
return ;
}

第三道:威佐夫游戏——黄金分割

基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难度:基础题
有2堆石子。A B两个人轮流拿,A先拿。每次可以从一堆中取任意个或从2堆中取相同数量的石子,但不可不取。拿到最后1颗石子的人获胜。假设A B都非常聪明,拿石子的过程中不会出现失误。给出2堆石子的数量,问最后谁能赢得比赛。
例如:2堆石子分别为3颗和5颗。那么不论A怎样拿,B都有对应的方法拿到最后1颗。
 
Input
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行2个数分别是2堆石子的数量,中间用空格分隔。(1 <= N <= 2000000)
Output
共T行,如果A获胜输出A,如果B获胜输出B。
Input示例
3
3 5
3 4
1 9
Output示例
B
A
A
//Asimple
#include <bits/stdc++.h>
//#define INF 0x3fffffff
#define swap(a,b,t) t = a, a = b, b = t
#define CLS(a, v) memset(a, v, sizeof(a))
#define debug(a) cout << #a << " = " << a <<endl
#define test() cout<<"=========="<<endl
using namespace std;
typedef long long ll;
const int maxn = +;
const double PI=acos(-1.0);
const ll mod = ;
const int INF = ( << ) ;
const int dx[] = {-, , , };
const int dy[] = { ,-, , };
ll n, m, res, ans, len, T, k, num, sum, t;
ll a[maxn];
//ll mod; void input() {
ios_base::sync_with_stdio(false);
cin >> T;
while( T -- ){
cin >> n >> m;
if( n>m ) {
t = n; n = m; m = t;
}
t = floor((m-n)*(+sqrt(5.0))/);
if( t == n ) cout << "B" << endl;
else cout << "A" << endl;
}
} int main(){
input();
return ;
}

51Nod 博弈模板题的更多相关文章

  1. 最大子矩阵和 51Nod 1051 模板题

    一个M*N的矩阵,找到此矩阵的一个子矩阵,并且这个子矩阵的元素的和是最大的,输出这个最大的值. 例如:3*3的矩阵:   -1 3 -1 2 -1 3 -3 1 2   和最大的子矩阵是:   3 - ...

  2. 51nod 1028 大数乘法 V2 【FFT模板题】

    题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...

  3. 51nod 1086背包问题V2 (完全背包模板题)

    1086 背包问题 V2 1 秒 131,072 KB 20 分 3 级题 题目描述 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1, ...

  4. [AHOI 2009] 维护序列(线段树模板题)

    1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec  Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...

  5. HDU 2222 AC自动机模板题

    题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...

  6. POJ2774 & 后缀数组模板题

    题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程 ...

  7. HDU 1251 Trie树模板题

    1.HDU 1251 统计难题  Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...

  8. HDU-3549 最大流模板题

    1.HDU-3549   Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...

  9. HDU 4280:Island Transport(ISAP模板题)

    http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...

随机推荐

  1. 【Zookeeper系列】zookeeper面试题(转)

    原文链接:https://segmentfault.com/a/1190000014479433 1.ZooKeeper是什么? ZooKeeper是一个分布式的,开放源码的分布式应用程序协调服务,是 ...

  2. PowerBI与Visio

    前言 如何在Power BI中使用Visio, 刚好最近微软推出了适用于Power BI 的 Visio自定义可视化对象预览,分享给大家. 我们先看一下效果:    通过自定义可视化对象,将Visio ...

  3. PCB画板总结

    最近几天完成了第一个PCB电路板.虽然器件不是很多,手动布线了4次才达到自己理想的效果. 但是还是有很多细节只有亲自拿到了自己做的板子,亲自焊接之后,才知道自己哪里不合适. 这是修改了4次之后的最终的 ...

  4. Solve Docker for Windows error: docker detected, A firewall is blocking file Sharing between Windows and the containers

    被这个“分享硬盘”问题烦了我好几个小时,终于在一个叫Marco Mansi外国人博客上找到解决方法了,真的很无奈 https://blog.olandese.nl/2017/05/03/solve-d ...

  5. linux 安装配置nexus以及maven私服应用

    ---------------------nexus---------------------- 1.编辑nexus脚本, 配置 RUN_AS_USER 参数vi /usr/local/src/nex ...

  6. Nestjs 上传文件

    Docs: https://docs.nestjs.com/techniques/file-upload 上传单文件 @Post('upload') @UseInterceptors(FileInte ...

  7. vue利用vue ui命令创建项目

    上次用git bash,用create 命令创建vue项目,这是玩个炫酷的------vue ui (前提是有安装node.js). 在目标文件  vue ui 可以看到他在8000端口出现了一个gu ...

  8. [daily] 比端口转发更高级的ssh device tunnel转发

    没有什么能够阻挡,你对自由的向往. 场景: 我有一台设备Server100,在某一个f复杂的内网里,需要多次ssh跳转可以访问到.但是它不能直接访问internet. 我现在需要在我的ssh路径上,搭 ...

  9. [qemu] qemu从源码编译安装

    环境:CentOS7-1804 下载最新的源码: ┬─[tong@T7:~/Src/thirdparty/PACKAGES]─[:: AM] ╰─>$ axel https://download ...

  10. 从光盘安装ubuntu系统

    参考博客: https://www.jianshu.com/p/7929e4911206