Codeforces Round #201.C-Alice and Bob
C. Alice and Bob
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output
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
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
Print a single line with the winner's name. If Alice wins print "Alice", otherwise print "Bob" (without quotes).
大意:
n(n<=100)个正数,每次从中取任意两个数,他们的差值如果在集合中没有就加入集合中,问最后集合中元素个数的奇偶性?
思路:
快被自己蠢哭了。。。。竟然把题目读成了取出两个数,然后放回去。。。。。
首先,要明白一点,最终谁获胜,需要确定还缺几个数(还能够生成多少数)
{k∗gcd(x,y) | k=1,2,..且 k∗gcd(x,y)<=y}
所以加入第三个数之后这个集合的新的最大公约数是gcd(gcd(x,y),Z),然后生成集合是以这个最大公约数的倍数来生成.
max{xi | 1<=i<=n}gcd{x1,x2,...xn}
代码:
#include<bits/stdc++.h>
using namespace std;
const int MAXN=130;
int a[MAXN];
int gcd(int x,int y)
{
if(y==0) return x;
return gcd(y,x%y);
}
int main()
{
int n;
cin>>n;
int m=-1;
for(int i=0;i<n;i++){
cin>>a[i];
m=max(m,a[i]);
}
sort(a,a+n);
int res=gcd(a[n-1],a[n-2]);
for(int i=n-3;i>=0;i--){
res=gcd(max(res,a[i]),min(res,a[i]));
if(res==1) break;
}
int total=m/res-n;
if(total%2) cout<<"Alice"<<endl;
else cout<<"Bob"<<endl;
}
Codeforces Round #201.C-Alice and Bob的更多相关文章
- Educational Codeforces Round 9 B. Alice, Bob, Two Teams 前缀和
B. Alice, Bob, Two Teams 题目连接: http://www.codeforces.com/contest/632/problem/B Description Alice and ...
- Codeforces Round #201 (Div. 2)C,E
数论: C. Alice and Bob time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- Codeforces Round #201 (Div. 2) - C. Alice and Bob
题目链接:http://codeforces.com/contest/347/problem/C 题意是给你一个数n,然后n个数,这些数互不相同.每次可以取两个数x和y,然后可以得到|x - y|这个 ...
- codeforce Codeforces Round #201 (Div. 2)
cf 上的一道好题: 首先发现能生成所有数字-N 判断奇偶 就行了,但想不出来,如何生成所有数字,解题报告 说是 所有数字的中最大的那个数/所有数字的最小公倍数,好像有道理:纪念纪念: #incl ...
- codeforces round #201 Div2 A. Difference Row
#include <iostream> #include <vector> #include <algorithm> using namespace std; in ...
- Codeforces Round#201(div1) D. Lucky Common Subsequence
题意:给定两个串,求出两个串的最长公共子序列,要求该公共子序列不包含virus串. 用dp+kmp实现 dp[i][j][k]表示以i结尾的字符串和以j结尾的字符串的公共子序列的长度(其中k表示该公共 ...
- Codeforces Round #201 (Div. 2). E--Number Transformation II(贪心)
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description You ar ...
- 数学--数论--Alice and Bob (CodeForces - 346A )推导
It is so boring in the summer holiday, isn't it? So Alice and Bob have invented a new game to play. ...
- Codeforces Round #557 (Div. 1) 简要题解
Codeforces Round #557 (Div. 1) 简要题解 codeforces A. Hide and Seek 枚举起始位置\(a\),如果\(a\)未在序列中出现,则对答案有\(2\ ...
随机推荐
- HDU-5238 Calculator
题目描述 给定一个关于 \(x\) 的表达式,形如下例:\(×4+2^3+8×6\) 按如下方法计算:\((((x×4)+2)^3+8)×6\) 运算符只有 加号,乘号,幂运算三种,给定的式子中有 \ ...
- git clone 含有子模块的项目
当一个 git 项目包含子模块(submodule) 时,直接克隆下来的子模块目录里面是空的. 有两种方法解决: 方法一 如果项目已经克隆到了本地,执行下面的步骤: 初始化本地子模块配置文件 git ...
- Adam作者大革新, 联合Hinton等人推出全新优化方法Lookahead
Adam作者大革新, 联合Hinton等人推出全新优化方法Lookahead 参与:思源.路.泽南 快来试试 Lookahead 最优化方法啊,调参少.收敛好.速度还快,大牛用了都说好. 最优化方 ...
- C# 文件基本操作
概括的说,File,FileInfo,FileStream是用于文件 I/O 的类,StreamReader是用于从流读取和写入流的类,使用之前都需using System.IO. 先定义一个TXT文 ...
- 转载:mysql数据库连接自动断开
转自:https://www.cnblogs.com/ay-a/p/10520425.html MySql连接空闲8小时自动断开引起的问题 一.问题描述 最近遇到了一个奇怪的MySql数据库问 ...
- Nginx默认配置语法
Nginx默认配置语法 1. 我们进入 /etc/nginx/目录下,打开 nginx.conf文件 2. 我们来解析下 这里面标签和各模块的作用 # 设置nginx服务的系统使用用户 user ...
- dedecms 后台栏目全部展开 包括三级栏目
include/typeunit.class.admin.php 搜索以下代码并删除 style='display:none'
- Windows 聚焦的锁屏壁纸设置为桌面壁纸
需求: Windows的锁屏壁纸偶尔遇到非常喜欢的壁纸,想设置为桌面壁纸. 步骤如下: 1. “Windows 聚焦”的锁屏壁纸都保存在隐藏文件夹 --- Assets里. a. 打开“资源管理器 b ...
- google的CacheBuilder缓存
适用性: 计算或检索一个值的代价很高,并且对同样的输入需要不止一次获取值的时候,就应当考虑使用缓存. 常用用法: LoadingCache<Key, Graph> graphs = Cac ...
- Django学习系列17:在模板中渲染待办事项
前面提到的问题中在表格中显示多个待办事项 是最后一个容易解决的问题.要编写一个新单元测试,检查模板是否也能显示多个待办事项: lists/tests.py def test_displays_all_ ...