题解:CodeForces 346A Alice and Bob[博弈/数论]
CodeForces 346A
A. Alice and Bob
time limit per test2 seconds
memory limit per test256 megabytes
inputstandard input
outputstandard 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
暑假真是无聊,不是吗?所以爱丽丝和鲍勃发明了一个新游戏来玩。规则如下。首先,他们获得一组不同的整数
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
第一行包含一个整数
Output
Print a single line with the winner's name. If Alice wins print Alice
, otherwise print Bob
(without quotes).
打印一行,输出获胜者的名字。如果爱丽丝获胜,则打印Alice
,否则打印Bob
(不带引号)。
Examples
input
2 2 3
output
Alice
input
2 5 3
output
Alice
input
3 5 6 7
output
Bob
Note
Consider the first test sample. Alice moves first, and the only move she can do is to choose
我的题解
我的解法就是先找到里面所有数的最大公因数
然后用最大的数除以这个最大公因数
就能算出这个数组最多能有多少个数字
进而求出他们能放进来的数字的多少
进而推断出这个游戏的赢家
注意:
求最大公因数的时候
不要写
g = std::min(std::__gcd(a[i],a[j]),g);
一定要
g = std::__gcd(std::__gcd(a[i],a[j]),g);
前者是有问题的! 我已经WA了好多发了
我的代码
#include <bits/stdc++.h> #define int long long int t,n,num; void solve() { std::cin >> n; std::vector<int> a(n); for(int i = 0 ; i < n ; i ++){ std::cin >> a[i]; } std::sort(a.begin(),a.end()); int g = std::__gcd(a[0],a[1]); for(int i = 0 ; i < n ; i ++) { for(int j = i ;j < n; j ++) { g = std::__gcd(std::__gcd(a[i],a[j]),g); } } if((a[n-1]/g - n)%2 == 0) std::cout << "Bob"; else std::cout << "Alice"; } signed main() { solve(); return 0; }
有什么出现纰漏的地方还请大家在评论区指出!谢谢!
posted on 2024-07-14 14:37 Jiejiejiang 阅读(34) 评论(0) 编辑 收藏 举报
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· AI与.NET技术实操系列(五):向量存储与相似性搜索在 .NET 中的实现
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 【硬核科普】Trae如何「偷看」你的代码?零基础破解AI编程运行原理
· 上周热点回顾(3.3-3.9)