日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

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

發布時間:2023/12/4 编程问答 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Ticket Game CodeForces - 1215D(博弈题,巴什博弈思维) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題意:兩個人玩游戲,通過輪流填數字(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(博弈题,巴什博弈思维)的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。