CF#201 div2 C Alice and Bob(number theory)
来源:互联网 发布:上海数据交易中心 面试 编辑:程序博客网 时间:2024/06/05 00:54
地址
http://codeforces.com/contest/347/problem/C
题意
给n个数(2 ≤ n ≤ 100),a1, a2, …, an (
每次可以从中取出两个数x,y,然后将 |x - y| ,加入到原来的数组中。
现在两个人来玩这个游戏,当其中一个人拿出任意两个数的差的绝对值都在原来的数组中,这个人就输了。
问最后谁赢。
解析
每个数的gcd,然后用其中最大的数/gcd就是用上规则能够凑成的数的数量,减掉n个数,然后判断奇偶就行了。
总结
如果早一点做过这题,大概沈阳那个签到题很快就能出了。。。
代码
#pragma comment(linker, "/STACK:1677721600")#include <map>#include <set>#include <cmath>#include <queue>#include <stack>#include <vector>#include <cstdio>#include <cstdlib>#include <cstring>#include <climits>#include <cassert>#include <iostream>#include <algorithm>#define pb push_back#define mp make_pair#define LL long long#define lson lo,mi,rt<<1#define rson mi+1,hi,rt<<1|1#define Min(a,b) ((a)<(b)?(a):(b))#define Max(a,b) ((a)>(b)?(a):(b))#define mem(a,b) memset(a,b,sizeof(a))#define FIN freopen("in.txt", "r", stdin)#define FOUT freopen("out.txt", "w", stdout)#define rep(i,a,b) for(int i=(a); i<=(b); i++)#define dec(i,a,b) for(int i=(a); i>=(b); i--)using namespace std;const int mod = 1e9 + 7;const double eps = 1e-8;const double ee = exp(1.0);const int inf = 0x3f3f3f3f;const int maxn = 1e6 + 10;const double pi = acos(-1.0);int readT(){ char c; int ret = 0,flg = 0; while(c = getchar(), (c < '0' || c > '9') && c != '-'); if(c == '-') flg = 1; else ret = c ^ 48; while( c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c ^ 48); return flg ? - ret : ret;}LL readTL(){ char c; int flg = 0; LL ret = 0; while(c = getchar(), (c < '0' || c > '9') && c != '-'); if(c == '-') flg = 1; else ret = c ^ 48; while( c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c ^ 48); return flg ? - ret : ret;}LL gcd(LL a, LL b){ return b == 0 ? a : gcd(b, a % b);}int main(){ #ifdef LOCAL FIN; #endif // LOCAL int n = readT(); LL d = readTL(); LL maxx = d; rep(i, 1, n - 1) { LL t = readTL(); maxx = Max(t, maxx); d = gcd(d, t); } LL num = maxx / d; num -= n; if (num % 2) { puts("Alice"); } else { puts("Bob"); } return 0;}
0 0
- CF#201 div2 C Alice and Bob(number theory)
- codeforces#347div2 C. Alice and Bob
- CF 6C Alice, Bob and Chocolate
- CF 346A Alice and Bob
- Codeforces Round #201 (Div. 2) C. Alice and Bob
- Codeforces Round #201 (Div. 2) C. Alice and Bob ( 数学
- codeforces 6C - Alice, Bob and Chocolate
- Round #6 C.Alice, Bob and Chocolate
- CodeForces 347 C. Alice and Bob
- Codeforces 6C. Alice, Bob and Chocolate
- CodeForces 6C - Alice, Bob and Chocolate
- Codeforces 347C Alice and Bob
- CodeForces 6C Alice, Bob and Chocolate
- 6C - Alice, Bob and Chocolate
- CodeForces 347 C. Alice and Bob
- Codeforces 347C - Alice and Bob
- codeforce 6C - Alice, Bob and Chocolate
- CodeForces 347C Alice and Bob
- 操作系统试验中有关页架的若干问题
- windows下的锁
- 【FastDev4Android框架开发】Volley完全解析之基础使用(二十六)
- iOS学习之关于#import导入补全问题
- 计算机进程
- CF#201 div2 C Alice and Bob(number theory)
- 操作系统文件管理
- SpringMVC注解@RequestParam全面解析
- iOS本地通知的实现
- Fiddler工具——手机抓包
- RecyclerView GridLayoutManager实现复杂的列数变化的布局
- MyEclipse下Maven的安装配置以及运行
- 9,累加思想与计数思想
- HUD 1394 归并求逆序数