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. python实战之爬取喜玛拉雅专辑信息

    import urllib.request import json from lxml import etree url='http://www.ximalaya.com/dq/8.ajax' hea ...

  2. AJPFX关于StringBuffer,StringBuilder类总结(二)

    StringBuffer,StringBuilder类 总结2需要注意的知识点:1):// String -- >StringBuffer        String s = "hel ...

  3. web前端怎么样才能入门

    web前端怎么样才能入门,首先我们要从什么是初级web前端工程师说起: 按照我的想法,我把前端工程师分为了入门.初级.中级.高级这四个级别: 入门级别指的是了解什么是前端(前端到底是什么其实很多人还是 ...

  4. element ui select组件和table做分页完整功能和二级联动效果

    <template> <div class="index_box"> <div class="search_box"> &l ...

  5. Python3中的输入输出

    input()函数 我们可以通过Python3解释器查看Python3中input()的含义: >>> type(input) <class 'builtin_function ...

  6. Chrome浏览器安装React developer tools

    1. 到 https://github.com/facebook/react-devtools 下载 react-devtools 2. 进入 react-devtools 目录 运行命令  npm ...

  7. Session/EntityManager is closed

    Hinbernate操作数据库必须要开启事务, 但是在添加事务的时候遇到这个问题也是郁闷, 说Session被关闭了, 而这个Session又是必须的. 关键是我并没有关闭, 也找不到是哪里被关闭了的 ...

  8. Eclipse Code Recommenders 自动补全(联想)神器

    Eclipse Code Recommenders 可以在eclipse市场中下载.自动补全.模糊匹配.非常有用!

  9. HTML中pre标签的用法

    我们经常会在要保持文本格式的时候使用pre标签,比如当我们要展示源代码的时候,只要放一个pre标签,然后把源代码直接复制,粘贴,然后在页面上就可以保持好格式.不会像放在其它标签里那样,把换行和空格都自 ...

  10. 11scrapy

    一. Scrapy基础概念 Scrapy是一个为了爬取网站数据,提取结构性数据而编写的应用框架,我们只需要实现少量的代码,就能够快速的抓取.Scrapy 使用了 Twisted异步网络框架,可以加快我 ...