zoukankan      html  css  js  c++  java
  • [博弈] 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 }
  • 相关阅读:
    zabbix 监控获取源码包的地址
    为MongoDB加集群验证的关键点
    Mongodb 集群加keyFile认证
    Prometheus完整的部署方案+实战实例
    如何让你的linux的命令行变得很炫
    redis实现加锁的几种方法示例详解
    phpquerylist 抓取数据详解
    mysql 主从配置,主-》windows,从-》centos6.5
    VMware 虚拟机centos下链接网络配置
    【Mysql】表链接
  • 原文地址:https://www.cnblogs.com/Comfortable/p/11182543.html
Copyright © 2011-2022 走看看