zoukankan      html  css  js  c++  java
  • CF 1215 D Ticket Game (博弈)

     链接:https://codeforces.com/problemset/problem/1215/D

    Monocarp and Bicarp live in Berland, where every bus ticket consists of nn digits (nn 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 n2n2 digits of this ticket is equal to the sum of the last n2n2 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 00 to 99. 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(2n2105)(2≤n≤2⋅105) — the number of digits in the ticket.

    The second line contains a string of nn digits and "?" characters — the ticket which Monocarp and Bicarp have found. If the ii-th character is "?", then the ii-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).

    #include <bits/stdc++.h>
    using namespace std;
    
    const int maxn=2e5+5;
    int n;
    char s[maxn];
    int ls, rs, x, y;
    
    int main()
    {
        scanf("%d", &n);
        scanf("%s", s+1);
        for(int i=1; i<=n/2; i++){
            if(s[i]=='?') x++;
            else ls+=s[i]-'0';
        }
        for(int i=n/2+1; i<=n; i++){
            if(s[i]=='?') y++;
            else rs+=s[i]-'0';
        }
        if(ls<rs){
            swap(ls, rs); swap(x, y);
        }
        if(ls==rs){
            printf("%s
    ", x==y? "Bicarp":"Monocarp");
        }
        else{
            if(x>=y) printf("Monocarp
    ");
            else printf("%s
    ", (y-x)%2==0 && ls-rs==(y-x)/2*9? "Bicarp":"Monocarp");
        }
        return 0;
    }
    View Code
  • 相关阅读:
    博客重构 / Blog Refactoring
    Microsoft Ajax Beta1 边学边用边补充 (Part 2 DragDropList)
    深入理解 ViewState
    十分钟内学会:无刷新的页面间导航
    从 ASP 到 ASP.NET (Part 1 学习什么)
    Microsoft Ajax Beta1 边学边用边补充 (Part 1 Debug)
    深入理解 ASP.NET 动态控件 (Part 1 感性认识)
    Microsoft Ajax Beta1 边学边用边补充 (Part 3 ITemplate)
    Blog Refactoring (Volume 2)
    从 ASP 到 ASP.NET (Part 3 后记)
  • 原文地址:https://www.cnblogs.com/Yokel062/p/11615314.html
Copyright © 2011-2022 走看看