【博弈+GCD】C. Alice and Bob
https://www.bnuoj.com/v3/contest_show.php?cid=9147#problem/C
【题意】
初始时有n个数,定义操作为从n个数中取出两个数x,y,如果|x-y|不在set中,操作就是合法的,并且把|x-y|加到set里。最后不能操作的人输。A和B轮流操作,A先手,问最后谁赢。
【思路】
通过观察发现6,8,10和3,4,5的情况其实是一样的,不同的是前者的每个数都是后者的2倍。所以可以想到与GCD有关,而且GCD本身也是辗转相减。所以就想到了GCD。最后很容易想到是简化成互质数后的max-n.
【Accepted】
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int n;
const int maxn=1e2+;
const int inf=0x3f3f3f3f;
int a[maxn];
typedef long long ll; int GCD(int a,int b)
{
return b==?a:GCD(b,a%b);
}
int main()
{
while(~scanf("%d",&n))
{
int mmax=-inf;
for(int i=;i<n;i++)
{
scanf("%d",&a[i]);
mmax=max(mmax,a[i]);
}
sort(a,a+n);
int gcd=GCD(a[],a[]);
for(int i=;i<n;i++)
{
gcd=GCD(gcd,a[i]);
}
int ans=mmax/gcd-n;
if(ans%==)
{
puts("Bob");
}
else
{
puts("Alice");
}
}
return ;
}
【博弈+GCD】C. Alice and Bob的更多相关文章
- 博弈 HDOJ 4371 Alice and Bob
题目传送门 题意:Alice和 Bob轮流写数字,假设第 i 次的数字是S[i] ,那么第 i+1 次的数字 S[i+1] = S[i] + d[k] 或 S[i] - d[k],条件是 S[i+1] ...
- Alice and Bob(博弈)
Alice and Bob Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users ...
- Foj 2296 Alice and Bob(博弈、搜索)
Foj 2296 Alice and Bob 题意 两个人博弈,规则如下:轮流取0~9中的数字,最后Alice所得的数字个数为1~n中,数位在Alice所取集合中出现奇数次的. 双方想获得尽量多,问A ...
- ACdream 1112 Alice and Bob(素筛+博弈SG函数)
Alice and Bob Time Limit:3000MS Memory Limit:128000KB 64bit IO Format:%lld & %llu Submit ...
- ZOJ 3529 A Game Between Alice and Bob 博弈好题
A Game Between Alice and Bob Time Limit: 5 Seconds Memory Limit: 262144 KB Alice and Bob play t ...
- ny788 又见Alice and Bob
又见Alice and Bob 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 集训生活如此乏味,于是Alice和Bob发明了一个新游戏.规则如下:首先,他们得到一个 ...
- E - Alice and Bob
time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...
- 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob
Alice and Bob Time Limit: 10000/5000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others) ...
- 2014 Super Training #6 A Alice and Bob --SG函数
原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...
- Alice and Bob(不断补充)
我之前做过一些博弈的题目,以为博弈都是DP,结果被坑了很多次,其实博弈有很多种,在此,把我见过的类型都搬上来. 1,HDU3951(找规律) 题意:把n枚硬币围成一个圆,让Alice和Bob两个人分别 ...
随机推荐
- Elasticsearch (1) - 索引库 文档 分词
创建索引库 ES的索引库是一个逻辑概念,它包括了分词列表及文档列表,同一个索引库中存储了相同类型的文档.它就相当于MySQL中的表,或相当于Mongodb中的集合. 关于索引这个语: 索引(名词):E ...
- hihocoder offer收割编程练习赛8 A 小Ho的强迫症
思路: 乱搞. 实现: #include <iostream> #include <cstdio> using namespace std; typedef long long ...
- jQuery选择器之可见性选择器
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...
- 在colab上运行style-transfer
1, 打开chrome浏览器,输入以下网址,打开风格转换主文件 https://colab.research.google.com/github/Hvass-Labs/TensorFlow-Tuto ...
- 管道命令和xargs的区别(经典解释) 自己的总结
1. 简介 之所以能用到这个命令,关键是由于很多命令不支 持|管道来传递参数,而日常工作中有有这个必要, 所以就有了xargs命令,例如:find /sbin -perm +700 |ls -l 这个 ...
- jq打印
1.引入jQuery.print.min.js 2.将需要打印的东西用div包起来 3. $(".printDiv").print();
- swfit:运算符重载 Operator Methods
Operator Methods Classes and structures can provide their own implementations of existing operators. ...
- Pygame - Python游戏编程入门
>>> import pygame>>> print(pygame.ver)1.9.2a0 如果没有报错,应该是安装好了~ 如果报错找不到模块,很可能是安装版本的问 ...
- VC-基础:常用的安全CRT函数
常用的安全CRT函数 安全CRT(C Runtime Library = C运行时间库)函数,是微软公司对C/C++语言的扩展.它在原来函数名后添加了“_s”后缀:一般返回出错代码:并将原来的函数返回 ...
- Xcode导入第三方库图文
Three20这个与facebook亲戚的开源库是蜚声iPhone开发界,很多App都有它的影子,主要是其真得是功能强大.那么如何将Three20库添加到自己的项目中应用呢?一种是Python命令方式 ...