E. Thanos Nim

题目链接

E. Thanos Nim

\(Alice\)\(Bob\) 正在玩一个关于石头的游戏。

共有 \(n\)\(n\) 为偶数)堆石头,其中第 \(i\) 堆最初含有 \(a_i\) 个石子。

他们轮流选择 \(\frac{n}{2}\)非空石子,每堆移除掉正数个的石子,从 \(Alice\) 开始。

不能执行操作的人将输掉游戏。

假设 \(Alice\)\(Bob\) 都足够聪明,你知道谁会赢得游戏吗?

输入格式

第一行包含一个整数 \(n\) (\(2\leq n \leq 50\)),\(n\) 为偶数

第二行包含 \(n\) 个正整数 \(a_1,\dots,a_n\) (\(1\leq a_1,\dots,a_n \leq 50\))

输出格式

AliceBob,表示最终赢家

样例输入

4
1 1 1 1

样例输出

Bob

解题思路

博弈论

设计必败态:当有一堆石子个数为 \(0\) 时,非零石子堆个数不小于 \(\frac{n}{2}\) 个,此时先手可以将选择的 \(\frac{n}{2}\) 堆石子全拿走,使后手必败。
考虑最小值的变化,对于先手来说如果最小值的数量大于 \(\frac{n}{2}\),则最小值必然会减少,则后手可以选择 \(\frac{n}{2}\) 堆全为最小值,此时最小值不变,同时最小值的数量仍大于 \(\frac{n}{2}\),即每次使最小值减少的都会是先手,当最小值减少到某一堆为 \(0\) 时,由于其最多减少为 \(0\) 的堆数为 \(\frac{n}{2}\),即此时非零石子堆个数不小于 \(\frac{n}{2}\) 个,故此时先手必败;反之,对于先手来说如果最小值的数量不大于 \(\frac{n}{2}\),可以选 \(\frac{n}{2}\) 堆石子全为最小值使后手必败

  • 时间复杂度:\(O(n)\)

代码

// Problem: E. Thanos Nim
// Contest: Codeforces - Codeforces Round #557 (Div. 2) [based on Forethought Future Cup - Final Round]
// URL: https://codeforces.com/contest/1162/problem/E
// Memory Limit: 256 MB
// Time Limit: 1000 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 n,x;
int mn=0x3f3f3f3f,cnt;
int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
    	cin>>x;
    	if(mn>x)mn=x,cnt=1;
    	else if(mn==x)cnt++;
    }
    puts(cnt>n/2?"Bob":"Alice");
    return 0;
}
posted @ 2022-04-29 16:30  zyy2001  阅读(52)  评论(0编辑  收藏  举报