zoukankan      html  css  js  c++  java
  • CodeForces

    题面

    time limit per test:1 second
    memory limit per test:256 megabytes
    input:standard input
    output:standard output

    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 (frac{n}{2}) digits of this ticket is equal to the sum of the last (frac{n}{2}) 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.

    **Input **

    The first line contains one even integer (n) ((2 le n le 2 cdot 10^{5}))— the number of digits in the ticket.

    The second line contains a string of (n) digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the (i)-th character is "?", then the (i)-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.

    Output

    If Monocarp wins, print "Monocarp" (without quotes). Otherwise print "Bicarp" (without quotes).

    Examples

    input

    4
    0523
    

    output

    Bicarp
    

    input

    2
    ??
    

    output

    Bicarp
    

    input

    8
    ?054??0?
    

    output

    Bicarp
    

    input

    6
    ???00?
    

    output

    Monocarp
    

    代码

    #include <bits/stdc++.h>
    
    using namespace std;
    
    
    int main() {
    
    #ifndef ONLINE_JUDGE
        freopen("in.txt", "r", stdin);
        freopen("out.txt", "w", stdout);
    #endif
        int n;
        char ch;
        int sum1 = 0, sum2 = 0, num1 = 0, num2 = 0;
        scanf("%d", &n);
        getchar();
        for (int i = 0; i < n; ++i) {
            scanf("%c", &ch);
            if (ch == '?') {
                if (i < n / 2) ++num1;
                else ++num2;
            } else {
                if (i < n / 2) sum1 += (ch - '0');
                else sum2 += (ch - '0');
            }
        }
    
    
        if(num1 == num2 && sum1 != sum2)
        {
            puts("Monocarp");
            return 0;
        }
        if(num1 == 0 && num2 == 0)
        {
            if(sum1 == sum2)puts("Bicarp");
            else puts("Monocarp");
            return 0;
        }
    
        if(sum1 == sum2){
            if(num1 == num2)puts("Bicarp");
            else puts("Monocarp");
        }else{
            if((num2 - num1)/2*9 == (sum1 - sum2)) puts("Bicarp");
            else puts("Monocarp");
        }
    }
    
  • 相关阅读:
    mongodb studio 3t 破解无限使用脚本
    香港低价linux虚拟主机,
    c#4.0 Task.Factory.StartNew 用法
    系统进不去怎么办?教你利用bootice工具引导修复系统
    用一个URL加一个JAVA壳做成一个安卓应用
    ANDROID开机动画分析
    你的Android不好用,都是因为这几点原因
    横竖屏切换时不销毁当前activity 和 锁定屏幕
    APP流氓大法之apk 静默安装
    设备管理器勾选后不能再取消了
  • 原文地址:https://www.cnblogs.com/YY666/p/11652382.html
Copyright © 2011-2022 走看看