题目描述

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.

输入

The first line contains one even integer n (2≤n≤2⋅105) — 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 ii-th character is "?", then the ii-th digit is erased. Note that there may be leading zeroes. The number of "?" characters is even.

输出

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

样例

输入样例

Input

4
0523

Output

Bicarp

Input

2
??

Output

Bicarp

Input

8
?054??0?

Output

Bicarp

Input

6
???00?

Output

Monocarp

分析

一句话题意:一张票有n位数,如果这张票的前一半数字的和等于后一半数字的和(n一定是偶数),就称这张票为快乐票。有些数被擦除了,标记为’?’(’?‘的个数也是偶数),现在Monocarp 和 Bicarp 进行一个游戏,两人轮流将’?'变换成0到9的任意一个数,Monocarp先手,如果最后票为快乐票则Bicarp赢,否则Monocarp赢。

我们分情况来考虑一下

1、左边的数字之和等于右边的数字之和

这时,如果左右两边?的个数相等的话,后手赢,因为先手无论放什么数,后手都可以放一个相同的数来平衡

如果不相等,则先手必胜,因为最后肯定只能在一边放,只要先手能放,就一定会打破平衡

2、左边的数字之和小于右边的数字之和

如果左边?的个数大于等于右边的个数,那么先手必胜,因为先手可以一直在左边放9,后手只能不断在右边放9维持差距,但始终不能弥补差距

如果左边?的个数小于右边的个数,我们设左边?的个数为a,右边?的个数为b,那么前2a回合,策略同上;2a回合之后,先手放一个数x,后手唯一的选择就是放一个y,使x+y=9,所以当左右两边数字之差为9的倍数时,后手胜,否则先手胜

3、右边的数字之和小于左边的数字之和(同上)

代码

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
using namespace std;
char c[300000];
int lefw,rigw,lef,rigt;
int main(){
int n;
scanf("%d",&n);
getchar();
for(int i=1;i<=n/2;i++){
scanf("%c",&c[i]);
if(c[i]=='?'){
lefw++;
} else {
lef+=(c[i]-'0');
}
}
for(int i=n/2+1;i<=n;i++){
scanf("%c",&c[i]);
if(c[i]=='?'){
rigw++;
} else {
rigt+=(c[i]-'0');
}
}
if(lef==rigt){
if(lefw==rigw) printf("Bicarp\n");
else printf("Monocarp\n");
}
else if(lef>rigt){
int cha=rigw-lefw;
if(cha<=0){
printf("Monocarp\n");
return 0;
}
int chaa=lef-rigt;
if(cha%2==0 && cha/2*9==chaa) printf("Bicarp\n");
else printf("Monocarp\n");
} else {
int cha=lefw-rigw;
if(cha<=0){
printf("Monocarp\n");
return 0;
}
int chaa=rigt-lef;
if(cha%2==0 && cha/2*9==chaa) printf("Bicarp\n");
else printf("Monocarp\n");
}
return 0;
}

Ticket Game CodeForces - 1215D 博弈题的更多相关文章

  1. Codeforces 1215D Ticket Game 题解

    Codeforces 1215D Ticket Game 原题 题目 Monocarp and Bicarp live in Berland, where every bus ticket consi ...

  2. hdu4678 Mine 2013 Multi-University Training Contest 8 博弈题

    Mine Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/32768 K (Java/Others) Total Submi ...

  3. [POJ1082&POJ2348&POJ1067&POJ2505&POJ1960]简单博弈题总结

    鉴于时间紧张...虽然知道博弈是个大课题但是花一个上午时间已经极限了... 希望省选过后再回过头来好好总结一遍吧. 接下来为了看着顺眼一点...还是按照难度顺序吧   POJ1082 一道最简单的博弈 ...

  4. Codeforces VP/补题小记 (持续填坑)

    Codeforces VP/补题小记 1149 C. Tree Generator 给你一棵树的括号序列,每次交换两个括号,维护每次交换之后的直径. ​ 考虑括号序列维护树的路径信息和,是将左括号看做 ...

  5. Codeforces 1215D. Ticket Game

    传送门 博弈,发现情况有点多,分析一下把有用的状态提取出来 显然各个位置的数字是没用的,我们只要知道两边的数字和分别是多少 并且状态显然和左右两边的 "?" 数量有关 因为最终我们 ...

  6. CodeForces - 427B (模拟题)

    Prison Transfer Time Limit: 1000MS   Memory Limit: 262144KB   64bit IO Format: %I64d & %I64u Sub ...

  7. codeforces #261 C题 Pashmak and Buses(瞎搞)

    题目地址:http://codeforces.com/contest/459/problem/C C. Pashmak and Buses time limit per test 1 second m ...

  8. Codeforces & Atcoder神仙题做题记录

    鉴于Codeforces和atcoder上有很多神题,即使发呆了一整节数学课也是肝不出来,所以就记录一下. AGC033B LRUD Game 只要横坐标或者纵坐标超出范围就可以,所以我们只用看其中一 ...

  9. B - Save the problem! CodeForces - 867B 构造题

    B - Save the problem! CodeForces - 867B 这个题目还是很简单的,很明显是一个构造题,但是早训的时候脑子有点糊涂,想到了用1 2 来构造, 但是去算这个数的时候算错 ...

随机推荐

  1. 微信小程序 简单获取屏幕视口高度

    由于小程序的宽度是固定的 750rpx,我们可以先用wx.getSystemInfo 来获取可使用窗口的宽高(并非rpx),结合750rpx的宽度算出比例,再用比例来算出高度 let that = t ...

  2. jdbc+mysql常见报错总结

    1.The server time zone value '�й���׼ʱ��' is unrecognized or represents more than one time zone. You ...

  3. 8000字长文让你彻底了解 Java 8 的 Lambda、函数式接口、Stream 用法和原理

    我是风筝,公众号「古时的风筝」.一个兼具深度与广度的程序员鼓励师,一个本打算写诗却写起了代码的田园码农! 文章会收录在 JavaNewBee 中,更有 Java 后端知识图谱,从小白到大牛要走的路都在 ...

  4. java第三阶段作业总结

    Java第三阶段总结 前言 到这里,Java课程学习进入了尾声,在这学习过程中,我学习到很多,也发现了自己的很多不足,这篇博客主要针对的是Java整门课程学习的总结. 课程收获 对整门课程的学习,我有 ...

  5. 关于宝塔面板ftp+sublime

    如果sublime通过ftp上传文件传不上去,我的问题在于应该把sftp-config.json中"remote_path": "/",设置成这样.一下午.哎呀 ...

  6. 如何解决在electron里无法使用puppeteer的evaluate函数

    报错如图,只需要注释掉 index.html 含有 http-equiv="Content-Security-Policy 的 meta 标签就可以了.

  7. Quartz.Net系列(二):介绍、简单使用、对比Windows计划任务

    1.介绍 Quartz是功能强大的开源作业调度库,几乎可以集成到任何Java应用程序中-从最小的独立应用程序到最大的电子商务系统.Quartz可用于创建简单或复杂的计划,以执行数以万计,数以万计的工作 ...

  8. VS Code项目中通过npm包的方式共享代码片段的方案实现

    VS Code项目中通过npm包的方式共享代码片段的方案实现 上周在 "VS Code项目中共享自定义的代码片段方案" 的文章中提到过一个共享代码片段的方案,上周经过调研后并没有发 ...

  9. 【JMeter_03】JMeter GUI操作界面介绍

    JMeter主界面主要分为 标题栏.菜单栏.工具栏.测试计划树形目录.内容展示区 标题栏:主要展示JMeter的程序版本.当前脚本的名称.脚本的储存路径 菜单栏:程序基本上所有功能的所属分类目录,基本 ...

  10. Laravel模板引擎Blade中section的一些标签的区别介绍

    Laravel 框架中的 Blade 模板引擎,很好用,但是在官方文档中有关 Blade 的介绍并不详细,有些东西没有写出来,而有些则是没有说清楚.比如,使用中可能会遇到这样的问题: 1.@yield ...