Codeforces 347C Alice and Bob
来源:互联网 发布:中文安卓编程王者荣耀 编辑:程序博客网 时间:2024/05/17 07:26
题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=46782
解题思路:首先对于a和b,如果b>a且gcd(a,b)=1的话,则按照游戏规则可以求解出1->b之间的所有整数,每次操作只能增加一个整数。
因此我们可以先求解出所有数的最大公约数,用最大的数除以最大公约数d则可以得到我们能够继续添加的数的数目,如果结果为奇数则第一个人赢,如果结果为偶数则第二个人赢。
#include <ctime>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;const int maxn = 110;int arr[maxn];int gcd(int a, int b) { return b == 0 ? a : gcd(b, a % b);}int main() { int n; int d = 0; scanf("%d", &n); for(int i = 1; i <= n; ++i) { scanf("%d", &arr[i]); d = gcd(d, arr[i]); } sort(arr + 1, arr + n + 1); int cnt = arr[n]/d - n; if(cnt % 2) { printf("Alice\n"); } else { printf("Bob\n"); } return 0;}
0 0
- CodeForces 347 C. Alice and Bob
- Codeforces 347C Alice and Bob
- CodeForces 347 C. Alice and Bob
- codeforces#347div2 C. Alice and Bob
- Codeforces 347C - Alice and Bob
- CodeForces 347C Alice and Bob
- CodeForces 347C Alice and Bob(博弈)
- codeforces 347 c Alice and Bob(博弈 && 数学)
- codeforces 6C - Alice, Bob and Chocolate
- Codeforces 6C. Alice, Bob and Chocolate
- CodeForces 6C - Alice, Bob and Chocolate
- CodeForces 6C Alice, Bob and Chocolate
- CodeForces 6C Alice, Bob and Chocolate
- Alice and Bob (CodeForces
- Alice and Bob CodeForces
- 【博弈】Alice and Bob CodeForces
- Alice, Bob and Chocolate CodeForces
- Codeforces Round #201 (Div. 2) C. Alice and Bob
- java生成随机数方法大全(可指定范围、分布方式、类型、种子)
- 用指针修改const变量问题
- powerdesignerz中批量根据对象的name生成comment的脚本
- Java算法-1.连通性问题
- tomcat 部署方式
- Codeforces 347C Alice and Bob
- VC: MBCS字符集转换成UTF-8
- 抽象类
- hdu3555(数位dp)
- hibernate4.0以上的hibernateUtil工具类
- Linux学习笔记一 ---- Linux基础知识认知以及初识Linux下C编程入门
- eclipse 不断报错:Computing Git status for repository
- 比较与整理GDI与GDIPlus抓取、合并和保存位图的方法
- Linux进程间的通信——管道