• Codeforces Round #585 (Div. 2) D. Ticket Game


    链接:

    https://codeforces.com/contest/1215/problem/D

    题意:

    Monocarp and Bicarp live in Berland, where every bus ticket consists of n digits (n is an even number). During the evening walk Monocarp and Bicarp found a ticket where some of the digits have been erased. The number of digits that have been erased is even.

    Monocarp and Bicarp have decided to play a game with this ticket. Monocarp hates happy tickets, while Bicarp collects them. A ticket is considered happy if the sum of the first n2 digits of this ticket is equal to the sum of the last n2 digits.

    Monocarp and Bicarp take turns (and Monocarp performs the first of them). During each turn, the current player must replace any erased digit with any digit from 0 to 9. The game ends when there are no erased digits in the ticket.

    If the ticket is happy after all erased digits are replaced with decimal digits, then Bicarp wins. Otherwise, Monocarp wins. You have to determine who will win if both players play optimally.

    思路:

    考虑两半, 如果和相等, 则?树也要相等.
    如果l>r, 则l的问号要小于r,同时两边的问号差为sub, 考虑为了补充右边等于左边, 如果左边较小则填较大使其不成立, 较大则填较小.所有只有差值为sub/2*9时成立.
    这样两人一起的贡献和为9.正好填充相等.

    代码:

    #include <bits/stdc++.h>
    using namespace std;
    
    string s;
    int n;
    
    int main()
    {
        cin >> n;
        cin >> s;
        int sum1 = 0, sum2 = 0, num1 = 0, num2 = 0;
        for (int i = 0;i < n;i++)
        {
            if (i < n/2)
            {
                if (s[i] == '?')
                    num1++;
                else
                    sum1 += s[i]-'0';
            }
            else
            {
                if (s[i] == '?')
                    num2++;
                else
                    sum2 += s[i]-'0';
            }
        }
        if (sum1 < sum2)
            swap(sum1, sum2), swap(num1,num2);
        if (sum1 == sum2)
        {
            if (num1 == num2)
                puts("Bicarp");
            else
                puts("Monocarp");
            return 0;
        }
        if (num1 > num2)
        {
            puts("Monocarp");
            return 0;
        }
        int need = sum1-sum2;
        int own = ((num2-num1)/2)*9;
        if (need != own)
            puts("Monocarp");
        else
            puts("Bicarp");
    
        return 0;
    }
    
  • 相关阅读:
    Java之集合类应用总结
    Java的HashMap和HashTable
    Java安全通信:HTTPS与SSL
    字符串如何排序
    HashMap泛型编程
    Java之currenHashMap
    Android游戏开发:游戏框架的搭建(1)
    Java安全通信概述
    嵌入式linux学习步骤
    图片水平无缝滚动的代码
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11634901.html
Copyright © 2020-2023  润新知