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;
    }
    
  • 相关阅读:
    STL的相关知识
    有关欧拉通路/回路的一些资料整理
    差分约束
    BZOJ 2100: [Usaco2010 Dec]Apple Delivery
    BZOJ 2017: [Usaco2009 Nov]硬币游戏(A Coin Game)
    vijos 1282&1283&1284&1285 佳佳的魔法照片/魔法药水/魔杖/魔法阵
    BZOJ 1660: [Usaco2006 Nov]Bad Hair Day
    BZOJ 1602: [Usaco2008 Oct]牧场行走
    BZOJ 1647: [Usaco2007 Open]Fliptile 翻格子游戏
    BZOJ 1646: [Usaco2007 Open]Catch That Cow
  • 原文地址:https://www.cnblogs.com/YDDDD/p/11634901.html
Copyright © 2011-2022 走看看