其他分享
首页 > 其他分享> > CodeFoeces 1215 D Ticket Game(数学,思维)

CodeFoeces 1215 D Ticket Game(数学,思维)

作者:互联网

CodeFoeces 1215 D Ticket Game

题目大意

M和B轮流玩游戏(每一轮M先手
现在给出一个长度为偶数的串,包含字符'?'和数字
现在两人依次在'?'上填数字\(0\)~\(9\)
若M先手,最后串的左右两部分数字之和相等,则B赢,反之M赢

solution

难得教练给一道稍稍简单的题QwQ
最好想的状态就是:

#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
// #include <cmath>
// #define int long long
using namespace std;

inline int read(){
    int x = 0, w = 1;
    char ch = getchar();
    for(; ch > '9' || ch < '0'; ch = getchar()) if(ch == '-') w = -1;
    for(; ch >= '0' && ch <= '9'; ch = getchar()) x = x * 10 + ch - '0';
    return x * w;
}

const int maxn = 55555;
char s[maxn];
int l, r;
int s1, s2;

int main(){
    int n = read();
    scanf("%s", s + 1);
    for(int i = 1; i <= n / 2; i++){
        if(s[i] == '?') l += 1;
        else s1 += s[i] - '0';
    }
    for(int i = n / 2 + 1; i <= n; i++){
        if(s[i] == '?') r += 1;
        else s2 += s[i] - '0';
    }
    if(s1 < s2){
        swap(s1, s2);
        swap(l, r);
    }
    if(s1 == s2){
        if(l == r) cout << "Biacarp" << '\n';
        else cout << "Monocarp" << '\n';
    }
    else{
        if(l >= r) cout << "Monocarp" << '\n';
        else printf("%s\n", (r - l) % 2 == 0 && s1 - s2 == (r - l) /2*9? "Bicarp":"Monocarp");
    }
}

标签:ch,数字,1215,int,CodeFoeces,反之,先手,Game,include
来源: https://www.cnblogs.com/rui-4825/p/12758810.html