CodeForces 346A Alice and Bob
来源:互联网 发布:网络公关团队 编辑:程序博客网 时间:2024/05/22 13:04
规律是最大数减n,奇数则Alice,偶数则Bob
关键:最大数要先除以所有数的公约数
例如:
3
5 6 7
可以如下
Alice:1(7-6) 5 6 7
Bob:1 2(7-5) 5 6 7
Alice:1 2 3(5-2) 5 6 7
Bob:1 2 3 4(6-2) 5 6 7
轮到Alice了,但所有数两两绝对值都包含在内了,所以Alice输
如果
3
10 12 14
最后一组会是
Bob:2 4 6 8 10 12 14
所以需要预先求出所有数的最大公约数
#include<stdio.h>#include<iostream>#include<math.h>#include<string.h>#include<iomanip>#include<stdlib.h>#include<ctype.h>#include<algorithm>#include<deque>#include<functional>#include<iterator>#include<vector>#include<list>#include<map>#include<queue>#include<set>#include<stack>#define CPY(A, B) memcpy(A, B, sizeof(A))typedef long long LL;typedef unsigned long long uLL;const int MOD = 1e9 + 7;const int INF = 0x3f3f3f3f;const LL INFF = 0x3f3f3f3f3f3f3f3fLL;const double EPS = 1e-9;const double OO = 1e20;const double PI = acos (-1.0);const int dx[] = {-1, 0, 1, 0};const int dy[] = {0, 1, 0, -1};using namespace std;LL a[110];LL gcd (LL a,LL b) { if (a == 0) { return 0;} else { return (b == 0) ? a : gcd (b, a % b);}}int main() { int n; LL maxn=0; scanf ("%d",&n); for (int i=0; i<n; i++) { scanf ("%I64d",&a[i]); maxn=max (a[i],maxn); } LL ans=maxn;/*the largest one*/ for (int i=0; i<n-1/*!*/; i++) { for (int j=i+1/*!*/; j<n; j++) { int t=gcd (a[i],a[j]); ans=gcd (ans,t);//gcd of all numbers } } printf ( ( ( (maxn/ans)-n) %2==1) ?"Alice\n":"Bob\n"); return 0;}
0 0
- [CodeForces 346A]Alice and Bob[数学]
- codeforces-346A-Alice and Bob【数论】
- CodeForces 346A Alice and Bob
- CodeForces 346A Alice and Bob
- Alice and Bob (CodeForces
- Alice and Bob CodeForces
- A:Alice and Bob
- CF 346A Alice and Bob
- Codeforce 346A. Alice and Bob
- 【博弈】Alice and Bob CodeForces
- Alice, Bob and Chocolate CodeForces
- A. Alice and Bob----最大公约数
- Codeforces Round #201 (Div. 1) / 346A Alice and Bob (数论&想法题)
- CF 346A(Alice and Bob-Python,sort)
- codeforces 6C - Alice, Bob and Chocolate
- CodeForces 347 C. Alice and Bob
- Codeforces 6C. Alice, Bob and Chocolate
- CodeForces 6C - Alice, Bob and Chocolate
- C++左值引用
- FrameLayout布局的增强版—CoordinatorLayout
- PreferenceActivity参数设置界面
- js 闭包方式封装
- C++11 | 正则表达式(3)
- CodeForces 346A Alice and Bob
- apache查看TCP并发连接数
- Android SplashActivity启动时黑屏的问题
- 如何成为优秀的驱动开发工程师
- C语言高级指针
- java.lang.ClassNotFoundException: Didn't find class "*****Activity" on path: /data/ap
- 路由跟踪工具:traceroute
- tcp/ip 多线程服务器端的实现(参考tcp/ip网络编程)
- Insight Properties