poj-2232 New Stone-Forfex-Cloth Game 思维题

Acm is a clever boy, and he developed a new game form the old Stone-Forfex-Cloth game.

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.
Input
The input contains several test cases. In each case, the first line contains an integer N (the number of children, 1 <= N <= 1000), and the second line contains N capitals including 'S', 'F' and 'C, which are separated by a single space and represent the gestures of N children in clockwise order. Here 'S' expresses the Stone, 'F' expresses the Forfex, and 'C' expresses the Cloth.
Output
For each case, output the total number of possible winners in a single line.
Sample Input
3
C S F
2
S C
4
S S S S
Sample Output
3
1
4

poj-2232;Caution_X;20191002;规律;-
description modelling:n个人围成一圈玩石头剪刀布,任选一人开始,逆时再任选一人玩石头剪刀布,输的人出圈,问最后留下的人有多少种情况;-
major steps to solve it:;-
考虑三种情况:;-
(1)所有人只出一个手势,那么任意一个人都有可能留下,答案为n;-
(2)所有人只出两种手势,虽然对手是任意挑选的,但是赢的人的手势是确定的,所以留下的人只能是出了能赢手势的人,此时答案为出了赢得手势的人的人数;-
(3)三种手势都有,显然任意一种手势,只要合理安排对手就一定能赢,所以此时答案还是n;-
warnings:A挑了B当对手,两人出相同手势,A赢;.

AC CODE:

#include
#include
#include<set>
#include
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){
            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;
}

 

你可能感兴趣的:(poj-2232 New Stone-Forfex-Cloth Game 思维题)