Loading [MathJax]/jax/output/CommonHTML/config.js
前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >数学--数论--Alice and Bob (CodeForces - 346A )推导

数学--数论--Alice and Bob (CodeForces - 346A )推导

作者头像
风骨散人Chiam
发布于 2020-10-28 02:09:22
发布于 2020-10-28 02:09:22
56300
代码可运行
举报
文章被收录于专栏:CSDN旧文CSDN旧文
运行总次数:0
代码可运行
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. The rules are as follows. First, they get a set of n distinct integers. And then they take turns to make the following moves. During each move, either Alice or Bob (the player whose turn is the current) can choose two distinct integers x and y from the set, such that the set doesn't contain their absolute difference |x - y|. Then this player adds integer |x - y| to the set (so, the size of the set increases by one).

If the current player has no valid move, he (or she) loses the game. The question is who will finally win the game if both players play optimally. Remember that Alice always moves first.

Input

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
The first line contains an integer n (2 ≤ n ≤ 100) — the initial number of elements in the set. The second line contains n distinct space-separated integers a1, a2,...,an (1 ≤ ai ≤ 109) — the elements of the set.

Output

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).

Examples

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Input
2
2 3
Output
Alice
Input
2
5 3
Output
Alice
Input
3
5 6 7
Output
Bob

Note

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Consider the first test sample. Alice moves first, and the only move she can do is to choose 2 and 3, then to add 1 to the set. Next Bob moves, there is no valid move anymore, so the winner is Alice.

游戏结束的标志是无法取出两个数字,他们的差值不在序列中。也就是说,最终状态是一个首项等于公差的等差序列。

求出这个等差数列的项数-n,就是游戏进行的回合。所以我们要先求出首项。设首项为d,接下来就是d+d,d+2d….

后面几项都是首项的倍数,所以我们可以用gcd(a1,a2,a3…an)求出。ans = an / gcd(a1,a2…an) - n;

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
#include <bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
	return b==0? a:gcd(b,a%b);
}
int a[101];
int main()
{
   int n;
   int maxn = 0;
   scanf("%d", &n);
   for(int i=0;i<n;i++)
     {
	  scanf("%d", &a[i]);
	  maxn = max(maxn, a[i]);
     }  
	int tmp = maxn;
    
	for(int i=0; i<n; i++)
     {
     	tmp = gcd(tmp,a[i]);
     }
   int x =  maxn/tmp - n;
   if(x%2==1)
   printf("Alice\n");
   else
   printf("Bob\n");
   return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2020/02/18 ,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
编辑精选文章
换一批
CF1405D「Tree Tag」
Alice and Bob are playing a fun game of tree tag.
hotarugali
2022/03/03
6340
Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
A. Mike and palindrome time limit per test:2 seconds memory limit per test:256 megabytes input:standard input output:standard output Mike has a string s consisting of only lowercase English letters. He wants to change exactly one character from the string
Angel_Kitty
2018/04/08
1.1K0
Codeforces Round #410 (Div. 2)(A,字符串,水坑,B,暴力枚举,C,思维题,D,区间贪心)
HDU 3032 Nim or not Nim?(Multi-Nim)
Problem Description Nim is a two-player mathematic game of strategy in which players take turns removing objects from distinct heaps. On each turn, a player must remove at least one object, and may remove any number of objects provided they all come f
attack
2018/04/10
1.3K0
公平组合游戏-巴什游戏、尼姆游戏和SG函数
公平组合游戏(Impartral Combinatorial Game)是满足以下特征的一类问题:
唔仄lo咚锵
2020/10/09
1.5K0
公平组合游戏-巴什游戏、尼姆游戏和SG函数
game theory博弈论全文翻译_john nash博弈论
Little John is playing very funny game with his younger brother. There is one big box filled with M&Ms of different colors. At first John has to eat several M&Ms of the same color. Then his opponent has to make a turn. And so on. Please note that each player has to eat at least one M&M during his turn. If John (or his brother) will eat the last M&M from the box he will be considered as a looser and he will have to buy a new candy box.
全栈程序员站长
2022/11/10
4270
数学--数论--HDU 4675 GCD of Sequence
先放知识点: 莫比乌斯反演 卢卡斯定理求组合数 乘法逆元 快速幂取模 GCD of Sequence Alice is playing a game with Bob. Alice shows N integers a 1, a 2, …, a N, and M, K. She says each integers 1 ≤ a i ≤ M. And now Alice wants to ask for each d = 1 to M, how many different sequences b
风骨散人Chiam
2020/11/06
3130
Codeforces Round #483 (Div. 2) A. Game
Initially there are nn integers a1,a2,…,ana1,a2,…,an written on the board. Each turn a player selects one number and erases it from the board. This continues until there is only one number left on the board, i. e. n−1n−1 turns are made. The first player makes the first move, then players alternate turns.
用户2965768
2018/08/30
5180
cf(#div1 B. Dreamoon and Sets)(数论)
B. Dreamoon and Sets time limit per test 1 second memory limit per test 256 megabytes input st
Gxjun
2018/03/26
6620
cf(#div1 B. Dreamoon and Sets)(数论)
P3507 [POI2010]GRA-The Minima Game
题目描述 Alice and Bob learned the minima game, which they like very much, recently. The rules of the game are as follows. A certain number of cards lies on a table, each inscribed with a positive integer. The players make alternate moves, Alice making the fir
attack
2018/04/13
6910
图论--2-SAT--HDU/HDOJ 4115 Eliminate the Conflict
Problem Description Conflicts are everywhere in the world, from the young to the elderly, from families to countries. Conflicts cause quarrels, fights or even wars. How wonderful the world will be if all conflicts can be eliminated. Edward contributes hi
风骨散人Chiam
2020/10/28
4810
Codeforces Beta Round #2 A,B,C
A. Winner time limit per test:1 second memory limit per test:64 megabytes input:standard input output:standard output The winner of the card game popular in Berland "Berlogging" is determined according to the following rules. If at the end of the game ther
Angel_Kitty
2018/04/08
1.1K0
hdu 4268 Alice and Bob(multiset|段树)
Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 2901    Accepted Submission(s): 941
全栈程序员站长
2022/01/17
2240
hdu 4315 Climbing the Hill(阶梯博弈转nim博弈)
Climbing the Hill Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 919    Accepted Submission(s): 411 Problem Description Alice and Bob are playing a game called "Climbing the Hill". The game board c
Gxjun
2018/03/26
8850
Code force-CodeCraft-20 (Div. 2) D. Nash Matrix 详解(DFS构造)
D. Nash Matrix time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output Nash designed an interesting yet simple board game where a player is simply required to follow instructions written on the cell where the player currently stands.
风骨散人Chiam
2020/10/28
3190
CF1608C「Game Master」
There are two different maps in the game. For each player, we know his strength on each map. When two players fight on a specific map, the player with higher strength on that map always wins. No two players have the same strength on the same map.
hotarugali
2022/03/18
3890
Codeforces Round #629 (Div. 3) F. Make k Equal (技巧暴力,类前缀和,思维,数学)
You are given the array aa consisting of nn elements and the integer k≤nk≤n.
glm233
2020/09/28
4670
Codeforces Round #336 (Div. 2)【A.思维,暴力,B.字符串,暴搜,前缀和,C.暴力,D,区间dp,E,字符串,数学】
A. Saitama Destroys Hotel time limit per test:1 second memory limit per test:256 megabytes input:standard input output:standard output Saitama accidentally destroyed a hotel again. To repay the hotel company, Genos has volunteered to operate an elevator in
Angel_Kitty
2018/04/09
9810
POJ 2891 Strange Way to Express Integers
Description Elina is reading a book written by Rujia Liu, which introduces a strange way to express non-negative integers. The way is described as following: Choose k different positive integers a1, a2, …, ak. For some non-negative m, divide it by ever
attack
2018/04/11
8020
CodeForces - 1047CEnlarge GCD(这题很难,快来看题解,超级详细,骗浏览量)
C. Enlarge GCD time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Mr. F has n positive integers, a1,a2,…,an.
风骨散人Chiam
2020/10/28
5000
HDUOJ------2492Ping pong
Ping pong Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Submission(s): 3518    Accepted Submission(s): 1299 Problem Description N(3<=N<=20000) ping pong players live along a west-east street(consider the stree
Gxjun
2018/03/22
7540
推荐阅读
相关推荐
CF1405D「Tree Tag」
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档
本文部分代码块支持一键运行,欢迎体验
本文部分代码块支持一键运行,欢迎体验