In this game, a number of children sit in a circle, each one shows a gesture (one of the Stone, the Forfex and the Cloth), which can't be changed in the whole game. Then a randomly chosen child (we call him player A) compares his gesture with the one on his anticlockwise (we call him play B) direction. And the loser should jump out of the circle. This operation continues until there is only one child left, which is the winner. Of course the winner is decided by both the gestures the children show and the order to compare. Your task is to tell the total number of possible winners.
The game obeys the following rulers:
1. Forfex beat Cloth.
2. Cloth beat Stone.
3. Stone beat Forfex.
4. If it is a draw, play A wins.
3 C S F 2 S C 4 S S S SSample Output
3 1 4
poj-2232; Caution_X; 20191002; Law; -
Description Modeling: n-play individual circle stone scissors cloth, optionally one starts, then counterclockwise optionally one playing stone scissors cloth, loser a circle, leaving the final Q how many people under the circumstances; -
Major Steps to the Solve IT:; -
consider three cases:; -
(1) everyone only a gesture, then any one person that could have left, the answer to the n-; -
( 2) everyone only two kinds of gestures, although the opponent is chosen at random, but to win people's gestures are determined, so the only people left are the people win gesture, then the answer is a win the number of people gestures; -
(3) three gestures have, obviously any gesture, as long as reasonable arrangements opponent will win, so in this case the answer is the n-; -
Represents warnings: a pick B when the opponent, the two the same gesture, A win;.
AC CODE:
#include<iostream> #include<cstdio> #include<set> #include<map> using namespace std; char a[1010]; set<char> book; map<char,int> list; int main() { //freopen("input.txt","r",stdin); int n; while(~scanf("%d",&n)){ int cnt=0; for(int i=0;i<n;i++){ cin>>a[i]; list[a[i]]++; book.insert(a[i]); } if(book.size()==1||book.size()==3) printf("%d\n",n); else if(book.size()==2) { if(list['C']!=0&&list['S']!=0) printf("%d\n",list['C']); else if(list['F']!=0&&list['S']!=0) printf("%d\n",list['S']); else if(list['C']!=0&&list['F']!=0) printf("%d\n",list['F']); } list.clear(); book.clear(); } return 0; }