AtCoder Regular Contest 137

题目链接

AtCoder Regular Contest 137

C - Distinct Numbers

Problem Statement

You are given a non-negative integer sequence of length N:A=(A1,A2,,AN). Here, all elements of A are pairwise distinct.
Alice and Bob will play a game. They will alternately play a turn, with Alice going first. In each turn, the player does the operation below.

  • Choose the largest element in A at the moment, and replace it with a smaller non-negative integer. Here, all elements in A must still be pairwise distinct after this operation.
    The first player to be unable to do the operation loses. Determine the winner when both players play optimally.
    Constraints
  • 2N3×105
  • 0A1<A2<<AN109
  • All values in input are integers.

Input

Input is given from Standard Input in the following format:

N A1 A2 ... AN

Output

If Alice wins, print Alice; if Bob wins, print Bob.

Sample Input 1

2 2 4

Sample Output 1

Alice

In Alice's first turn, she may replace 4 with 0, 1, or 3. If she replaces 4 with 0 or 1, Bob's move in the next turn will make Alice unable to do the operation and lose. On the other hand, if she replaces 4 with 3, she can win regardless of Bob's subsequent moves. Thus, Alice wins in this input.

Sample Input 2

3 0 1 2

Sample Output 2

Bob

解题思路

博弈论

  • 如果 a[n]a[n1]2,先手必胜
    证明:如果存在一种方案将 a[n] 变为小于 a[n1] 的数必胜,有两种情况:1.小于 a[n1] 的数都不能选,则先手可以选择将 a[n] 变为 a[n1]+1 使后手无数可选;2.有小于 a[n1] 的数可选,则先手选择一个小于 a[n1] 使其必胜。否则所有将 a[n] 变为小于 a[n1] 的数必败,先手可以选择将 a[n] 变为 a[n1]+1 使后手处于必败局面

  • a[n]a[n1]=1
    为了不使后手处于必胜局面,先手要保证每一次操作后最大值与次最大值之间相差为 1,每次操作最大值都要减小,最终必败局面为 0,1,,n1,即 a[n](n1) 的奇偶性决定最后的胜者

  • 时间复杂度:O(1)

代码

// Problem: C - Distinct Numbers // Contest: AtCoder - AtCoder Regular Contest 137 // URL: https://atcoder.jp/contests/arc137/tasks/arc137_c // Memory Limit: 1024 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; } const int N=300005; int n,a[N]; int main() { cin>>n; for(int i=1;i<=n;i++)cin>>a[i]; bool f=0; if(a[n]-a[n-1]>=2)f=1; else if((a[n]-(n-1))%2)f=1; puts(f?"Alice":"Bob"); return 0; }

__EOF__

本文作者acwing_zyy
本文链接https://www.cnblogs.com/zyyun/p/16032554.html
关于博主:评论和私信会在第一时间回复。或者直接私信我。
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!
声援博主:如果您觉得文章对您有帮助,可以点击文章右下角推荐一下。您的鼓励是博主的最大动力!
posted @   zyy2001  阅读(210)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· 单线程的Redis速度为什么快?
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 展开说说关于C#中ORM框架的用法!
点击右上角即可分享
微信分享提示