POJ 3869 条件概率

传送门:http://poj.org/problem?id=3869

题意:

就是电影中常见的轮回传枪对着自己脑子的赌命游戏,0代表没子弹,1代表有子弹 左轮枪的梭子是圆的,所以注意判断最后一个到第一个管连着的,循环之外判断下就行了。

然后就是条件概率了。对手没打出子弹,是0,找出00/00+01,随机来一发就是0/n。其实00+01就是0的数量,这里的01都是连续的。

#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;

typedef long long ll;

int main()
{
    string str;
    freopen("headshot.in","r",stdin);
    freopen("headshot.out","w",stdout);
    while(cin>>str)
    {
        int a=0,b=0,c=0;
        int n=str.length();
        for(int i=0; i<n-1; i++)
        {
            if(str[i]=='0'&&str[i+1]=='0')
                a++;
            if((str[i]=='0'&&str[i+1]=='0')||(str[i]=='0'&&str[i+1]=='1'))
                c++;

            if(str[i]=='0')
                b++;
        }
        if(str[n-1]=='0')
            b++;
        if(str[n-1]=='0'&&str[0]=='0')
            a++;
        if((str[n-1]=='0'&&str[0]=='0')||(str[n-1]=='0'&&str[0]=='1'))
            c++;
        if(a*n>b*c)
            cout<<"SHOOT"<<endl;
        else if(a*n<b*c)
            cout<<"ROTATE"<<endl;
        else
            cout<<"EQUAL"<<endl;
    }
    return 0;
}

 

posted @ 2017-06-26 10:10  Lawliet__zmz  阅读(100)  评论(0编辑  收藏  举报