Title Link:Balloon Game
Main topic:
Alice and Bob play a game, they want to put balloons, to ensure that the color of the balloon all adjacent to appear, now in a sequence of balloons have been placed, and some are not placed, with "?" Said. For example: A?b?c, then finally we can be placed into AABBC,AABDC ...
Alice first placed the balloon, he wanted to make the balloon color of odd number, Bob put his hands on, want to let the number of colors to an even number, ask for each Ask Alice whether there is a winning strategy.
Topic Analysis:
The first time I read the topic, I feel that some situations can be solved for this game problem:
1. When the "a?...? appears A "In this case, the middle section has actually been determined to be" a ", so only if Alice and Bob do not want to change the other existing patterns of the balloon will be put one, and then they will alternately put color-determined balloons, so their parity can" reverse "the final result.
2. When the "a?...? appears B "In this case, if the initiator does not want to increase the color, it is possible to put a" a "in front of the last B, then this section of"? " became the situation also 1.
3. When the "a?...? appears B "In this case , if the initiator wants to increase the color, then it is crucial where he will add a new color. No matter where you add a new color, we'll split the "?...?" into two sequences, which we'll need to discuss in odd and even.
1) when "a?...? B "In the"? " The number is an even number, then add a color, it will be split into a odd and even two "???" Sequence. This is actually the case with a single "a?...? B "In the"? " The number is the same as an odd number.
2 "when" a?...? B "In the"? " The number is odd number, then add a color, it will be split into two even two "???" Sequence. This is actually the case with a single "a?...? B "In the"? " The number is the same as an even number.
But the reason why I didn't dare to do it in training was that I thought that there were only 26 colors to consider, so the judgment would be quite complicated, because we have to consider the number of colors left and so on ... But later saw hint in a sentence: "Though the showing colors in input case would only a
z
is-, can use any color." qaq~~~
So see the topic is still the most important AH ~
/*author:samsons date:2015.4.12*/#include<cstdio>#include<cstdlib>#include<cstring>#include<iostream>using namespacestd;intcolor[ -];intMain () {//freopen ("b.in", "R", stdin);memset (Color,0,sizeof(color)); Chartmp=' /'; intNum,num_s,num_n,num_co,ans,i; Num=0; num_s=0; num_n=0; num_co=0; Charch; while(SCANF ("%c", &ch)! =EOF) { if(ch=='?') {num++; Continue; } if(tmp!=ch) {Color[ch-'a']=1; Num_n+=num; TMP=ch; Num=0; } Else{color[ch-'a']=1; num_s+=num; TMP=ch; Num=0; }} num_n+=num; for(i=0;i< -; i++) if(color[i]==1) num_co++; if(num_n==0) { if(Num_co%2==1) {cout<<"Yes"<<Endl; } Else{cout<<"No"<<Endl; } return 0; } if(num_n==1) {cout<<"Yes"<<Endl; return 0; } ans=0; if(Num_n%2==1) ans=1; if(num_s%2==1) if(ans==1) ans=0; Elseans=1; if(ans==1) cout<<"Yes"<<Endl; Elsecout <<"No"<<Endl; return 0;}
UESTC794 Balloon Game game