D. Ticket Game (thinking + bash game)

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


Ideas:

If you take a stone, take 1, 2, .... There are conclusions every time. Similar here.

The first is if the two sides? Will you reach one side before the end? There is also a difference between the two sides.

At this point, the problem becomes a pile of stones for you, each time you can take 1, 2,...9. Who wins first and second. Just look at %9.

There is also a small restriction here is that everyone has to take the remaining? Quantity/2 times.

Think of it this way, that is to say, regardless of whether A takes x, what B can guarantee is to take y as 9-x, that is, it can only guarantee that it is a multiple of 9. A total of n/2 times, that is, n/2*9==sum, B wins. Otherwise, A wins

#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
char a[maxn],b[maxn],s[maxn];
LL tot1=0,tot2=0;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
int main(void)
{
  LL n;cin>>n;
  scanf("%s",s+1);
  for(LL i=1;i<=n/2;i++) a[++tot1]=s[i];
  for(LL i=n/2+1;i<=n;i++) b[++tot2]=s[i];

  LL sum1=0;LL qnum1=0;
  for(LL i=1;i<=tot1;i++){
    if(a[i]=='?') qnum1++;
    if(a[i]>='0'&&a[i]<='9') sum1+=(a[i]-'0');
  }
  LL sum2=0;LL qnum2=0;
  for(LL i=1;i<=tot2;i++){
    if(b[i]=='?') qnum2++;
    if(b[i]>='0'&&b[i]<='9') sum2+=(b[i]-'0');
  }
  LL numcnt=sum1-sum2;
  if(numcnt==0){
    if(qnum1==qnum2) cout<<"Bicarp"<<"\n";
    else cout<<"Monocarp"<<"\n";
  }
  else{
    if(numcnt>0){
        LL res=(qnum2-qnum1)/2;
        if(res*9==numcnt) cout<<"Bicarp"<<"\n";
        else cout<<"Monocarp"<<"\n";
    }
    else if(numcnt<0){
        LL res=(qnum1-qnum2)/2;
        if(res*9==abs(numcnt)) cout<<"Bicarp"<<"\n";
        else cout<<"Monocarp"<<"\n";
    }
  }
return 0;
}

 

Guess you like

Origin blog.csdn.net/zstuyyyyccccbbbb/article/details/114949444