• Codeforces Round #557 (Div. 2)E. 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 aiai stones.

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

    On a player's turn, they must choose exactly n2n2 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 n2n2 nonempty piles).

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

    Input

    The first line contains one integer nn (2n502≤n≤50) — the number of piles. It is guaranteed that nn is an even number.

    The second line contains nn integers a1,a2,,ana1,a2,…,an (1ai501≤ai≤50) — the number of stones in the piles.

    Output

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

    题目大概意思就是,有n堆石头,2个人每次可以取走n/2推石头中任意石头,大于0,当石头推小于n/2时,输

    emmmmm,就是一道博弈题,这堆石头的最小值为x,x的推数为m,当m<=n/2时,Alice可以将剩下的大于m的数变为m,也就是说,Alice强迫Bob将m的值减小,而他最多减小n/2,下一轮Alice继续重复这个过程

    直到m变为0,Alice获胜。代码如下

    #include <bits/stdc++.h>
    #define INF 0x3f3f3f3f
    const double PI=3.1415926535897931;
    const long long sale=1e9+10;
    const int MA= 1e7+10;
    const int ma= 2*1e5+10;
    const int few=1e3+10;
    using namespace std;
    //////////////////////////////////////////////
    int main()
    {
        int n;
        cin>>n;
        int a[ma];
        int minn=INF;
        for(int i=0; i<n; i++)
        {
            cin>>a[i];
            minn=min(minn,a[i]);
        }
        int cnt=0;
        for(int i=0; i<n; i++)
        {
            if(minn==a[i])
                cnt++;
        }
        if(cnt<=n/2)
            cout<<"Alice"<<endl;
        else
            cout<<"Bob"<<endl;
        return 0;
    }
  • 相关阅读:
    select,epoll,poll比较(网络资源总结)
    c++(重载、覆盖、隐藏)
    TCP状态转换图
    TCP心跳 | TCP keepAlive
    回车、换行、空格的ASCII码值—(附ASCII码表)
    C++ dlopen mini HOWTO 一篇非常好的介绍
    shell十三问
    linux IPC消息队列 的内核限制
    C++ string 类常用函数
    const用法的解惑
  • 原文地址:https://www.cnblogs.com/Aracne/p/12189516.html
Copyright © 2020-2023  润新知