51Nod 博弈模板题
连刷3道博弈模板题,算是稍微学习了以下三个经典博弈了。推荐一个博客。
第一道模板:Bash博弈——同余理论
第1行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行2个数N,K。中间用空格分隔。(1 <= N,K <= 10^9)
共T行,如果A获胜输出A,如果B获胜输出B。
4
3 2
4 2
7 3
8 3
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行:一个数N,表示有N堆石子。(1 <= N <= 1000)
第2 - N + 1行:N堆石子的数量。(1 <= A[i] <= 10^9)
如果A获胜输出A,如果B获胜输出B。
3
1
1
1
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行:一个数T,表示后面用作输入测试的数的数量。(1 <= T <= 10000)
第2 - T + 1行:每行2个数分别是2堆石子的数量,中间用空格分隔。(1 <= N <= 2000000)
共T行,如果A获胜输出A,如果B获胜输出B。
3
3 5
3 4
1 9
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 博弈模板题的更多相关文章
- 最大子矩阵和 51Nod 1051 模板题
一个M*N的矩阵,找到此矩阵的一个子矩阵,并且这个子矩阵的元素的和是最大的,输出这个最大的值. 例如:3*3的矩阵: -1 3 -1 2 -1 3 -3 1 2 和最大的子矩阵是: 3 - ...
- 51nod 1028 大数乘法 V2 【FFT模板题】
题目链接 模板题.. #include<bits/stdc++.h> using namespace std; typedef int LL; typedef double db; nam ...
- 51nod 1086背包问题V2 (完全背包模板题)
1086 背包问题 V2 1 秒 131,072 KB 20 分 3 级题 题目描述 有N种物品,每种物品的数量为C1,C2......Cn.从中任选若干件放在容量为W的背包里,每种物品的体积为W1, ...
- [AHOI 2009] 维护序列(线段树模板题)
1798: [Ahoi2009]Seq 维护序列seq Time Limit: 30 Sec Memory Limit: 64 MB Description 老师交给小可可一个维护数列的任务,现在小 ...
- HDU 2222 AC自动机模板题
题目: http://acm.hdu.edu.cn/showproblem.php?pid=2222 AC自动机模板题 我现在对AC自动机的理解还一般,就贴一下我参考学习的两篇博客的链接: http: ...
- POJ2774 & 后缀数组模板题
题意: 求两个字符串的LCP SOL: 模板题.连一起搞一搞就好了...主要是记录一下做(sha)题(bi)过程心(cao)得(dan)体(xin)会(qing) 后缀数组概念...还算是简单的,过程 ...
- HDU 1251 Trie树模板题
1.HDU 1251 统计难题 Trie树模板题,或者map 2.总结:用C++过了,G++就爆内存.. 题意:查找给定前缀的单词数量. #include<iostream> #incl ...
- HDU-3549 最大流模板题
1.HDU-3549 Flow Problem 2.链接:http://acm.hdu.edu.cn/showproblem.php?pid=3549 3.总结:模板题,参考了 http://ww ...
- HDU 4280:Island Transport(ISAP模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=4280 题意:在最西边的点走到最东边的点最大容量. 思路:ISAP模板题,Dinic过不了. #include & ...
随机推荐
- navicat for mysql cant connect to server 10038 远程连接出错
使用的登录账号没有开通远程登录的权限,所以只能在服务器上通过命令行登录. 解决办法如下:1.在服务器上通过命令行或客户端登录mysql:2.执行以下sql:GRANT ALL PRIVILEGES O ...
- hue 记录
No databases are available. Permissions could be missing. Could not start SASL: Error in sasl_client ...
- springBoot整合ftp上传图片功能
知识点: springBoot后端项目,接收前端框架传到的图片,把图片上传到ftp图片服务器上 注意:在上传的过程中可能回出现,可以创建文件夹,但是图片上传不了的问题: 尝试了网上的很多方法,最后将f ...
- win10 安装mysql
现在mysql压缩包:https://downloads.mysql.com/archives/community/ 在目录下新建data文件夹,my.ini文件,内容如下: [mysqld] bas ...
- Postgresql 查看锁的过程
一.查看sql语句是否发生死锁 1.查看数据库的进程.SELECT * FROM pg_stat_activity WHERE datname='死锁的数据库ID ';检索出来的字段中,[wating ...
- python的time
有时候需要获取并格式化输出把当前时间,需要用到datetime的strftime方法 >>from datetime import datetime >>datetime.no ...
- WebH
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Net ...
- swp文件已存在
vim编辑某个文件时,提示.xxx.sh.swp文件已存在是因为异常退出后,linux会生成一个swp文件,无论选择什么,下次进入还是会提示ll 命令无法看到文件使用 rm -rf .xxx.sh.s ...
- WebService,ESB笔记
一.WebService是什么? WebService,是RPC的一样实现方式. RPC(Remote Procedure Call Protocol)--远程过程调用协议,它是一种通过网络从远程计算 ...
- day19:常用模块(collections,time,random,os,sys)
1,正则复习,re.S,这个在用的最多,re.M多行模式,这个主要改变^和$的行为,每一行都是新串开头,每个回车都是结尾.re.L 在Windows和linux里面对一些特殊字符有不一样的识别,re. ...