【博弈+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两个人分别 ...
随机推荐
- Scala基础篇-05求值策略
Scala的求值策略有2种: call by value call by name 如何区分? 例子: def bar(x:Int,y: => Int) = def loop(): Int=lo ...
- fsck和badlocks
fsck可以检查好几种不同的文件系统,fsck只是一个中和程序而已,个别的文件系统检查程序都在/sbin中,可以使用ls -l /sbin/fsck* -A 按照/etc/fstab的内容,将所有的设 ...
- java访问数据库步骤详解
eg1: public static void main(String[] args) throws ClassNotFoundException, SQLException { //第一步:加载JD ...
- 微信小程序开发系列四:微信小程序之控制器的初始化逻辑
微信小程序开发系列教程 微信小程序开发系列一:微信小程序的申请和开发环境的搭建 微信小程序开发系列二:微信小程序的视图设计 微信小程序开发系列三:微信小程序的调试方法 这个教程的前两篇文章,介绍了如何 ...
- leetcode_268.missing number
给定一个数组nums,其中包含0--n中的n个数,找到数组中没有出现的那个数. 解法一:cyclic swapping algorithm class Solution { public: int m ...
- Android(java)学习笔记181:多媒体之图片画画板案例
1.首先我们编写布局文件activity_main.xml如下: <RelativeLayout xmlns:android="http://schemas.android.com/a ...
- shift Alt + up(down) copy current line ! ctrl + j show the control # vscode key
shift Alt + up(down) copy current line ! ctrl + j show the control # vscode key
- gocode安装不上的解决办法
mkdir -p $GOPATH/src/golang.org/x //路径下创建此文件 cd $GOPATH/src/golang.org/x //切换到此目录 git clone ht ...
- No-3.Linux 终端命令格式
Linux 终端命令格式 01. 终端命令格式 command [-options] [parameter] 说明: command:命令名,相应功能的英文单词或单词的缩写 [-options]:选项 ...
- [BZOJ3211]:花神游历各国(小清新线段树)
题目传送门 题目描述: 花神喜欢步行游历各国,顺便虐爆各地竞赛.花神有一条游览路线,它是线型的,也就是说,所有游历国家呈一条线的形状排列,花神对每个国家都有一个喜欢程度(当然花神并不一定喜欢所有国家) ...