zoukankan      html  css  js  c++  java
  • 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;
    }
    
  • 相关阅读:
    Mybatis Cause: java.lang.ClassNotFoundException: Cannot find class:
    java常见面试题及部分答案
    页面css样式找不到问题
    深入分析Java I/O的工作机制 (二)
    深入分析Java I/O的工作机制 (一)
    LifecycleProcessor not initialized
    几个java小例子
    idea 过段时间java程序包不存在问题 ?
    使用HttpClient发送Get/Post请求 你get了吗?
    Convert PIL Image to byte array?
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11634901.html
Copyright © 2011-2022 走看看