POJ 2232 New Stone-Forfex-Cloth Game(水题。必须读懂题,找个规律而已)

题意:一堆小朋友坐成一个圈,玩剪刀石头布游戏。
游戏规则:
1.小朋友的手势不能改变,随机选取小朋友与逆时针方向的人比较。
2.比较规则:剪刀石头布的游戏规则,输的那个人跳出圈子,直到只剩余一人,游戏结束。注意:遇到两个人出的手势一样的情况的话,别选中的那个人胜出,被比较的人跳出圈子。
3.计算一下,这样的随机的抽取的情况,最后一个胜出的人有几种可能性。

分析:
这题的坑挖的可是很深的,主要就是在读题上,有一句话非常重要,就因为对这句话理解失误,连续WA了好多次,,注意,谨慎。

 

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. 


 

题意说随机抽取一个逆时针比较,负者出局,
重复上过程是指 
 while人数>1 
begin 
随机抽; 
比较; 
踢出; 
end

 而不是 
 随机抽; 
while人数>1
 begin
比较; 
踢出;
 end 

开始自己就被这段东西给阴死了…………

然后,思路,如果3个手势都有的话,那么每个人都会有赢的可能性,这个是必须的,结果是n
            如果只有2个手势,那么手势胜利的那一方的个数就是结果
            如果只有一个手势的话,不用问了,结果也一定是n

贴下代码:
(256k,0ms)
#include<iostream>
using  namespace  std;
int  main()
{
    int num;
    char * a;
    int s , f , c , flag;
    while( cin >> num)
    {
        flag = 0;
        s = f = c = 0;
        a = new char [ num ];
        for( int i = 0; i < num; i ++)
        {
            cin >> a [ num ];
            if( a [ num ] == 'S')s ++;
            else  if( a [ num ] == 'F') f ++;
            else  if( a [ num ] == 'C') c ++;
        }
        if(s == num|| f == num|| c == num)
            flag = num;
        else if(s != 0 && f != 0 && c != 0)
            flag = num;
        else
        {
            if(s == 0) flag = f;
            else  if( f == 0) flag = c;
            else  if( c == 0) flag =s;
        }
        cout << flag << endl;
    }
}

你可能感兴趣的:(POJ 2232 New Stone-Forfex-Cloth Game(水题。必须读懂题,找个规律而已))