1. 程式人生 > >Gym-101308H/POJ3869 Headshot 思維+概率

Gym-101308H/POJ3869 Headshot 思維+概率

這道題其實很水。。但是英語太差了題目讀不懂55555...

題目中說一開始已經轉了一下打了一槍,結果沒事,說明當前點是“0”。如果直接打:有“00”和“01”兩種情況,沒事的概率就是“00/(00+01)”;如果先轉,那麼轉到的點可能是0,可能是1,沒事的概率就是“0/len(串長)”。比較這兩個概率就可以了。另外注意它是一個環。

附上AC程式碼:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define ll long long
typedef pair<int,int>pp;
#define mkp make_pair
#define pb push_back
const int INF=0x3f3f3f3f;
const ll MOD=1e9+(ll)7;

int main()
{
    freopen("headshot.in","r",stdin);
    freopen("headshot.out","w",stdout);
    char s[105];
    while(~scanf("%s",s))
    {
        int l=strlen(s);
        int n0=0;
        int n00=0,n01=0;
        for(int i=0;i<l-1;i++)
        {
            if(s[i]=='0')
                n0++;
            if(s[i]=='0'&&s[i+1]=='0')
                n00++;
            if(s[i]=='0'&&s[i+1]=='1')
                n01++;
        }
        if(s[l-1]=='0')
            n0++;
        if(s[l-1]=='0'&&s[0]=='0')
            n00++;
        if(s[l-1]=='0'&&s[0]=='1')
            n01++;
        double p1=n00*1.0/(n00+n01);
        double p2=n0*1.0/l;
        if(p1>p2)
            printf("SHOOT\n");
        else if(p1<p2)
            printf("ROTATE\n");
        else
            printf("EQUAL\n");
    }
	return 0;
}