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=\left(A_{1}, A_{2}, \cdots, A_{N}\right)\). 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
  • \(2 \leq N \leq 3 \times 10^{5}\)
  • \(0 \leq A_{1}<A_{2}<\cdots<A_{N} \leq 10^{9}\)
  • 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[n-1]\geq 2\),先手必胜
    证明:如果存在一种方案将 \(a[n]\) 变为小于 \(a[n-1]\) 的数必胜,有两种情况:1.小于 \(a[n-1]\) 的数都不能选,则先手可以选择将 \(a[n]\) 变为 \(a[n-1]+1\) 使后手无数可选;2.有小于 \(a[n-1]\) 的数可选,则先手选择一个小于 \(a[n-1]\) 使其必胜。否则所有将 \(a[n]\) 变为小于 \(a[n-1]\) 的数必败,先手可以选择将 \(a[n]\) 变为 \(a[n-1]+1\) 使后手处于必败局面

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

  • 时间复杂度:\(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;
}
posted @ 2022-03-20 22:47  zyy2001  阅读(180)  评论(0编辑  收藏  举报