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的更多相关文章

  1. 博弈 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] ...

  2. Alice and Bob(博弈)

    Alice and Bob Time Limit: 1000ms, Special Time Limit:2500ms, Memory Limit:65536KB Total submit users ...

  3. Foj 2296 Alice and Bob(博弈、搜索)

    Foj 2296 Alice and Bob 题意 两个人博弈,规则如下:轮流取0~9中的数字,最后Alice所得的数字个数为1~n中,数位在Alice所取集合中出现奇数次的. 双方想获得尽量多,问A ...

  4. ACdream 1112 Alice and Bob(素筛+博弈SG函数)

    Alice and Bob Time Limit:3000MS     Memory Limit:128000KB     64bit IO Format:%lld & %llu Submit ...

  5. 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 ...

  6. ny788 又见Alice and Bob

    又见Alice and Bob 时间限制:1000 ms  |  内存限制:65535 KB 难度:3   描述 集训生活如此乏味,于是Alice和Bob发明了一个新游戏.规则如下:首先,他们得到一个 ...

  7. E - Alice and Bob

    time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standa ...

  8. 2016中国大学生程序设计竞赛 - 网络选拔赛 J. Alice and Bob

    Alice and Bob Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) ...

  9. 2014 Super Training #6 A Alice and Bob --SG函数

    原题: ZOJ 3666 http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3666 博弈问题. 题意:给你1~N个位置,N是最 ...

  10. Alice and Bob(不断补充)

    我之前做过一些博弈的题目,以为博弈都是DP,结果被坑了很多次,其实博弈有很多种,在此,把我见过的类型都搬上来. 1,HDU3951(找规律) 题意:把n枚硬币围成一个圆,让Alice和Bob两个人分别 ...

随机推荐

  1. 为localhost添加https

    1.按照https://stackoverflow.com/a/7184031/4619958来做 其中,CommonName填写localhost 2.在ssl.conf里头加上 <Direc ...

  2. OpenGL 透视投影推导图解

    有它足够了,转载自:http://blog.sina.com.cn/s/blog_73428e9a0102v920.html

  3. 洛谷P2774 方格取数问题(最小割)

    题意 $n \times m$的矩阵,不能取相邻的元素,问最大能取多少 Sol 首先补集转化一下:最大权值 = sum - 使图不连通的最小权值 进行黑白染色 从S向黑点连权值为点权的边 从白点向T连 ...

  4. jQuery选择器之子元素选择器

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-type" content ...

  5. ArcGIS Desktop新建postgresql版sde(10.4.1)的连接

    假设连接到的sde数据库是pg数据库,其他参数包括: ip:10.0.0.8 数据库:sde1 用户:sde 密码:sde 打开catalog,新建数据库连接 按如下输入数据库连接参数 红框1是数据库 ...

  6. java实现斐波那契的两种方法

    package com.ywx.count; /** * 斐波那契数列(地推方式要比递归方式的效率要高) * @author Vashon(yangwenxue) * date:20150320 */ ...

  7. Oracle Storage in Action : 删除物理数据文件

    ALTER TABLESPACE XH_DM DROP DATAFILE 'F:\DEV\ORACLE-DATA\ORCL\XH_DM_1.DBF'; SQL> ALTER TABLESPACE ...

  8. NSValue的个人想法

    通过下面的代码,又可以将NSValue转换成CGRect,CGPoint等类型的数值. CGRect imageRect = [[self.lockImageRectArray objectAtInd ...

  9. 洛谷 P2912 [USACO08OCT]牧场散步Pasture Walking

    题目描述 The N cows (2 <= N <= 1,000) conveniently numbered 1..N are grazing among the N pastures ...

  10. (转)Spring如何装配各种集合类型的属性

    http://blog.csdn.net/yerenyuan_pku/article/details/52858499 在前面我们已经会注入基本类型对象和其他bean,现在我们就来学习如何注入各种集合 ...