original link - http://codeforces.com/contest/1215/problem/D
题意:
一个由数字和问好组成的字符串,两个人依次填数字,第一个人要左右两边相同,第二个人要不同,问最后谁赢了。
解析:
考虑第一个人的角度,显然我要让一边超过另外一边就是答案,所以我的填充方式一定是一边全是9,一边全是0。基于这种攻击方式,第二个人一定会让全是9的那边小,全是0的那边大。所以攻击两边的情况都做一遍判断一下即可。
代码:
/*
* Author : Jk_Chen
* Date : 2019-09-17-09.30.01
*/
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define rep(i,a,b) for(int i=(int)(a);i<=(int)(b);i++)
#define per(i,a,b) for(int i=(int)(a);i>=(int)(b);i--)
#define mmm(a,b) memset(a,b,sizeof(a))
#define pb push_back
#define pill pair<int, int>
#define fi first
#define se second
#define debug(x) cerr<<#x<<" = "<<x<<'\n';
const LL mod=1e9+7;
const int maxn=2e5+9;
LL rd(){ LL ans=0; char last=' ',ch=getchar();
while(!(ch>='0' && ch<='9'))last=ch,ch=getchar();
while(ch>='0' && ch<='9')ans=ans*10+ch-'0',ch=getchar();
if(last=='-')ans=-ans; return ans;
}
/*_________________________________________________________begin*/
char x[maxn];
int main(){
int n=rd();
gets(x+1);
int l=0,r=0;
int p=0,q=0;
rep(i,1,n/2)
if(x[i]=='?')p++;
else l+=x[i]-'0';
rep(i,n/2+1,n)
if(x[i]=='?')q++;
else r+=x[i]-'0';
bool win=0;
int tmp[2]={l,r};
int canl,canr;
if(p%2)
canl=(p+1)/2,
canr=(q+1)/2;
else
canl=p/2,
canr=q/2;
l+=canl*9,r+=canr*9;
if(l>r)win=1;
l=tmp[0],r=tmp[1];
if(q%2)
canr=(q+1)/2,
canl=(p+1)/2;
else
canr=q/2,
canl=p/2;
r+=canr*9,l+=canl*9;
if(r>l)win=1;
if(win)printf("Monocarp\n");
else printf("Bicarp\n");
return 0;
}
/*_________________________________________________________end*/