[博弈] Codeforces 1147C Thanos Nim

 

题目描述

Alice and Bob are playing a game with nn piles of stones. It is guaranteed that nn is an even number. The ii-th pile has a_iai stones.

Alice and Bob will play a game alternating turns with Alice going first.

On a player's turn, they must choose exactly \frac{n}{2}2n nonempty piles and independently remove a positive number of stones from each of the chosen piles. They can remove a different number of stones from the piles in a single turn. The first player unable to make a move loses (when there are less than \frac{n}{2}2nnonempty piles).

Given the starting configuration, determine who will win the game.

输入输出格式

输入格式:

 

The first line contains one integer nn ( 2 \leq n \leq 502n50 ) — the number of piles. It is guaranteed that nn is an even number.

The second line contains nn integers a_1, a_2, \ldots, a_na1,a2,,an ( 1 \leq a_i \leq 501ai50 ) — the number of stones in the piles.

 

输出格式:

 

Print a single string "Alice" if Alice wins; otherwise, print "Bob" (without double quotes).

 

输入输出样例

输入样例#1:
2
8 8
输出样例#1:
Bob
输入样例#2:
4
3 1 4 1
输出样例#2:
Alice

 

题解

  • 我们先考虑到了什么情况某人必胜或必败,显然如果一个人先取完一堆石子,另一个人只用将n/2堆石子取完,然后先取完一堆石子的人就无法取到n/2堆石子
  • 所以先取完一堆石子的人必败,我们首先先对每堆石子的石子数排序,设最少石子数相同的有num堆
  • 以下我们就分两种情况来讨论答案,一种是num>n/2,一种是num<=n/2
  • ①num>n/2,这个时候我们可以发现,无论先手怎么取,后手都可以把当前状态下的最小石子数的堆数保持在n/2堆上,这样的话,先手必定先会取完一堆石子,所以后手必胜
  • ②num<=n/2,我们首先排好序,前后分两段,然后先手可以把后一段取成前一段一样,然后后手怎么取,我们都将其先排序,将后n/2堆变成前n/2堆一样的数量,所以先手必胜

代码

 1 #include <iostream>
 2 #include <cstdio>
 3 const int N=55,inf=1e9;
 4 int n,mn=inf,cnt,a[N];
 5 using namespace std;
 6 int main()
 7 {
 8     scanf("%d",&n);
 9     for (int i=1;i<=n;i++) scanf("%d",&a[i]),mn=min(mn,a[i]);
10     for (int i=1;i<=n;i++) if (a[i]==mn) cnt++;
11     if (cnt<=n/2) puts("Alice"); else puts("Bob");
12 }

 

转载于:https://www.cnblogs.com/Comfortable/p/11182543.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值