Game theory-small game (a bit of thinking two)

Then look at the topic first:

A ticket has n digits. If the sum of the first half of the ticket is equal to the sum of the second half of the ticket (n must be an even number), the ticket is called a happy ticket. Some numbers have been erased, and the number marked as "?" (The number of "?" Is even), now Monocarp and Bicarp play a game, the two will take turns to transform "?" Into any number from 0 to 9, Monocarp first If the last ticket is a happy ticket, Bicarp wins, otherwise Monocarp wins.

This question is really boring.

The idea is a simulation.

Idea: front and back? Pairwise, the pairing becomes the same number, the rest? On the other side, if the digital sum is also greater than the other side, then Monocarp wins, otherwise

Look? The two-to-two sum becomes 9 (if? The odd number left, Monocarp wins) is the front equal to the back, if yes, Bicarp wins, otherwise Monocarp wins;

I gave you the idea.

Small details: be sure to find all the situations, otherwise it is easy to hang.

Here is the code:

 1 #include <cstdio>
 2 #include <algorithm>
 3 #include <cmath>
 4 using namespace std;
 5 int ans1,cnt1,ans2,cnt2;
 6 int main(){
 7     //freopen("a.in","r",stdin);
 8     int n;scanf("%d\n",&n);
 9     int m=n/2;
10     for(int i=1;i<=n;i++){
11         char ch;scanf("%c",&ch);
12         if(i<=m){
13             if(ch=='?')cnt1++;
14             else ans1+=ch-'0';
15         }
16         else {
17             if(ch=='?')cnt2++;
18             else ans2+=ch-'0';
19         }
20     } 
21     if(cnt1==cnt2){
22         if(ans1==ans2)printf("Bicarp");
23         else printf("Monocarp");
24     }
25     else if(cnt1>cnt2){
26         if(ans1>=ans2)printf("Monocarp");
27         else {
28             int shu=cnt1-cnt2,zhi=ans2-ans1;
29             if(shu%2==1||zhi%9!=0||(zhi/9)!=shu/2)printf("Monocarp");
30             else printf("Bicarp");
31         }
32     }
33     else {
34         if(ans2>=ans1)printf("Monocarp");
35         else {
36             int shu=cnt2-cnt1,zhi=ans1-ans2;
37             if(shu%2==1||zhi%9!=0||(zhi/9)!=(shu+1)/2)printf("Monocarp");
38             else printf("Bicarp");
39         }
40     }
41     return 0;
42 } 

 

Guess you like

Origin www.cnblogs.com/DZN2004/p/12758729.html