题意:两个人玩游戏,通过轮流填数字(0~9),若最终左右两边的和相等,后手赢,否则先手赢。起始有部分数字和空格。

官方题解:

题解翻译:

让我们把余额表示为左半部分数字和右半部分数字和的差。也让我成为最小可能的余额(如果我们用00的左半部替换所有的问号和99的右半部分中的所有问号都可以计算),让RR成为最大可能的平衡。

当且仅当l+r2=0l+r2=0时,第二个玩家获胜。我们就票子上剩下的问号做归纳证明吧。

如果所有的字符都是数字,那么第二个玩家只有在票子满意的情况下才能获胜,也就是当L+R2=0L+R2=0时。

好吧,现在假设问号是偶数,现在轮到第一个玩家了。每转一圈,R-LR-L的值减小99,并且可以将LL设置为从当前LL到L+9L+9的任意数字。如果l+r>0l+r>0,那么第一个玩家可以使ll尽可能大,并将其设置为l+9l+9。第二个玩家在回合中能做的最好的事情是将r r设置为r-9r-9(保持l l不变),l+rl+r的值将与前两回合相同。L+R<0L+R<0的情况也可作类似分析。在l+r=0l+r=0的情况下,第二个玩家有一个对称的策略。

我的理解:类似于巴什博弈,考虑后手赢的情况,其余情况则为先手赢。

此题要注意两个问题,一:要填的空格,二:起始两边的和的大小;

若只考虑后手赢的情况,有两个阶段。一,两边都有空格时:先手为了让自己赢,在和大的一边放9,后手也只能在和小的这一边放9,则两边,和差sum,空格差k都不变;

二:只有一边有空格且另一边的和较大:因为不知先手放啥,特殊放0或9,故每一回合(k/2)保持放九个,故只有(k/2)*9==sum时,后手才会赢。

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 00to 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 nn (2≤n≤2⋅105)(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).

Examples

Input

4
0523

Output

Bicarp

Input

2
??

Output

Bicarp

Input

8
?054??0?

Output

Bicarp

Input

6
???00?

Output

Monocarp

Note

Since there is no question mark in the ticket in the first example, the winner is determined before the game even starts, and it is Bicarp.

In the second example, Bicarp also wins. After Monocarp chooses an erased digit and replaces it with a new one, Bicap can choose another position with an erased digit and replace it with the same digit, so the ticket is happy.

ac代码:

#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
using namespace std;
const int M=2e5+10;
char s[M];
int main()
{int n;while(~scanf("%d",&n)){int x=0,y=0,z=0,a=0,b=0,c=0;scanf("%s",s+1);for(int i=1; i<=n/2; i++)if(s[i]=='?')x++;elsea+=s[i]-'0';for(int i=n/2+1; i<=n; i++)if(s[i]=='?')y++;elseb+=s[i]-'0';c=b-a;z=x-y;if(z%2)printf("Monocarp\n");else{z>>=1;//因为不知先手放啥,特殊放0或1,故每次保持放九个,类似巴什博弈if(z*9==c)printf("Bicarp\n");elseprintf("Monocarp\n");}}return 0;
}

Ticket Game CodeForces - 1215D(博弈题,巴什博弈思维)相关推荐

  1. 博弈论(巴什博弈,威佐夫博弈,尼姆博弈)

    文章目录 一.巴什博弈 二.威佐夫博弈 三.尼姆博弈 一.巴什博弈 一堆n个物品,两个人从中轮流取出1~m个,最后取关者胜. 同余定理:n=K*(m+1)+r;先取者拿走r个,那么后者无论拿走(1~m ...

  2. 博弈题解题思路及典例

    解题思路与步骤: 首先明确,博弈是不公平游戏,跟玩家无关,只与当前所出状态有关,即状态确定,结果也就确定了. 需要明确以下几点: 所有的终结点是必败点(即若当前处于必败点,则无论下一步怎么走,都必输无 ...

  3. hdu 2149 巴什博弈

    http://acm.hdu.edu.cn/showproblem.php?pid=2149 分析:就是巴什博弈的概念. 题目要求:对于每组数据,在一行里按递增的顺序输出Lele第一次可以加的价.两个 ...

  4. 杭电acm 1846 Brave Game(巴什博弈)

    Brave Game                             Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768 ...

  5. 巴什博弈--Nim游戏

    人机博弈: 现有21根火柴.每次只能取走1~4根.取走最后一根火柴的人输.人先取,计算机后取.要求设计一个程序进行人机对弈,使得计算机一方为"常胜将军". 思路分析: (巴什博弈) ...

  6. 题解报告:hdu 2188 悼念512汶川大地震遇难同胞——选拔志愿者(巴什博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2188 Problem Description 对于四川同胞遭受的灾难,全国人民纷纷伸出援助之手,几乎每 ...

  7. 【巴什博弈】HDOJ2188悼念512汶川大地震遇难同胞——选拔志愿者

    链接:http://acm.hdu.edu.cn/showproblem.php?pid=2188 巴什博弈的模板题,代公式就可以了. a代表目标捐款额,b代表每次能捐的最大额度.那么如果当a是b+1 ...

  8. 题解报告:hdu 1846 Brave Game(巴什博弈)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1846 Problem Description 十年前读大学的时候,中国每年都要从国外引进一些电影大片, ...

  9. 博弈论学习之巴什博弈,尼姆博弈, sg博弈

    博弈论真是一个神奇的东西,感觉和博弈论厉害的人玩游戏绝对会输. 这个博客讲的很好很全面 此类问题一般有如下特点: 1.博弈模型为两人轮流决策的非合作博弈.即两人轮流进行决策,并且两人都使用最优策略来获 ...

最新文章

  1. js学习总结----crm客户管理系统之项目开发流程和api接口文档
  2. Linux 高可用(HA)集群之keepalived详解
  3. Matlab字符串的基本操作
  4. 腾讯业务监控的修炼之路
  5. UML统一建模语言知识体系概述
  6. 鸿蒙系统可以替代安卓吗,华为今天发布的鸿蒙系统,到底能不能替代安卓?
  7. 学习笔记整理之StringBuffer与StringBulider的线程安全与线程不安全
  8. lightoj 1026 无向图 求桥
  9. 【英语学习】【Daily English】U13 Holiday L02 That's supposedly the best time of year to go
  10. OpenGL基础知识的理解
  11. thinkphp实现文章访问量计数器
  12. 百度地图行政区划遮罩+描点+信息窗demo
  13. 气象研究中的大气稳定性 Atmosphere stability
  14. 基于MES的生产车间管理信息系统
  15. 周志华机器学习(一)
  16. React Reconciler
  17. 练手小项目(1)——智能聊天机器人
  18. 开放redis指定端口连接方法
  19. linux 网卡virbr0,Linux网络配置
  20. 海量智库第3期|Vastbase G100核心技术介绍之【CSN事务快照】

热门文章

  1. Android面试题总结加强再加强版(三)
  2. 看得懂的设计模式 享元模式python3 最基本(简单)实现
  3. 可以通过发声把玻璃震碎吗?
  4. 一个孩子能长大成人到底有多不容易? | 今日最佳
  5. 将历史、数学、语文、地理、政治知识融会贯通的诀窍就是它
  6. 现在的便签本都这么社会了!?重复写万次还能云端保存
  7. android activity解耦,Android与设计模式:用单一职责原则为Activity解耦
  8. php curl hostname,php – 如何解决cURL错误(7):无法连接到主机?
  9. css-6 df15,webpack 样式文件的代码分割(15)
  10. linux 装nano命令,linux下安装 nano 如果没有这个命令的话~~可以看下