GDCPC广东省大学生程序设计竞赛
2022/7/3 14:20:12
本文主要是介绍GDCPC广东省大学生程序设计竞赛,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
比赛链接
GDCPC广东省大学生程序设计竞赛
G.Good Game, GG
\(Alice\) 和 \(Bob\) 玩一场游戏,给定 \(n\) 个整数。
\(Alice\) 有两种操作:
① 选一个奇数,将其分成两个整数
② 拿掉一个 \(1\)
\(Bob\) 只有 $1 $种操作:选择一个偶数并且将这个偶数拆分成两个数
\(Alice\) 为先手,判断谁是winner。
解题思路
博弈论
首先对于 \(1\),只能 \(Alice\) 操作而 \(Bob\) 不能操作,对 \(2\),\(Bob\) 只能将其拆成 \(1,1\),这样反而 \(Alice\) 还比 \(Bob\) 多操作一次,\(Bob\) 肯定不会操作 \(2\),故相当于 \(2\) 没用,而 \(奇数=奇数+偶数\),故对于 \(Alice\) 来说,如果 \(奇数 x\neq 1\) 的话,其必定会构造出一个偶数,这样最好是给 \(Bob\) 构造无用的 \(2\),其操作数为 \(\frac{x+1}{2}\);而对于偶数 \(x\),\(Bob\) 一定会划分为两个偶数,以划分为 \(x-2,2\) 为例,其操作数为 \(\frac{x}{2}-1\),比较两操作数即可
- 时间复杂度:\(O(n)\)
代码
// Problem: Good Game, GG // Contest: NowCoder // URL: https://ac.nowcoder.com/acm/contest/36906/G // Memory Limit: 524288 MB // Time Limit: 2000 ms // // Powered by CP Editor (https://cpeditor.org) // %%%Skyqwq #include <bits/stdc++.h> //#define int long long #define help {cin.tie(NULL); cout.tie(NULL);} #define pb push_back #define fi first #define se second #define mkp make_pair using namespace std; typedef long long LL; typedef pair<int, int> PII; typedef pair<LL, LL> PLL; template <typename T> bool chkMax(T &x, T y) { return (y > x) ? x = y, 1 : 0; } template <typename T> bool chkMin(T &x, T y) { return (y < x) ? x = y, 1 : 0; } template <typename T> void inline read(T &x) { int f = 1; x = 0; char s = getchar(); while (s < '0' || s > '9') { if (s == '-') f = -1; s = getchar(); } while (s <= '9' && s >= '0') x = x * 10 + (s ^ 48), s = getchar(); x *= f; } int t,n,x; int main() { for(cin>>t;t;t--) { cin>>n; LL cnt1=0,cnt2=0; while(n--) { cin>>x; if(x&1)cnt1+=x+1>>1; else cnt2+=x/2-1; } puts(cnt1>cnt2?"Alice":"Bob"); } return 0; }
这篇关于GDCPC广东省大学生程序设计竞赛的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2024-05-15PingCAP 黄东旭参与 CCF 秀湖会议,共探开源教育未来
- 2024-05-13PingCAP 戴涛:构建面向未来的金融核心系统
- 2024-05-09flutter3.x_macos桌面os实战
- 2024-05-09Rust中的并发性:Sync 和 Send Traits
- 2024-05-08使用Ollama和OpenWebUI在CPU上玩转Meta Llama3-8B
- 2024-05-08完工标准(DoD)与验收条件(AC)究竟有什么不同?
- 2024-05-084万 star 的 NocoDB 在 sealos 上一键起,轻松把数据库编程智能表格
- 2024-05-08Mac 版Stable Diffusion WebUI的安装
- 2024-05-08解锁CodeGeeX智能问答中3项独有的隐藏技能
- 2024-05-08RAG算法优化+新增代码仓库支持,CodeGeeX的@repo功能效果提升