Since it is the first probability problem, serious to analyze it.
Test instructions
There is a revolver, which is randomly loaded or not loaded, and is represented by a 01 sequence. Now known to pull the first trigger without bullets, asked whether to continue to pull the trigger or random rotation of the buckle, that choice makes the second pull the trigger is not the probability of a bullet.
Analysis:
This is a conditional probability that the first time the trigger is known to be pulled without bullets.
Set the sequence length to n,00 sequence number of a,0 is the number of B
Then the second time if there is no bullet, it corresponds to the given sequence of two consecutive 0, the sample space is B, so the probability is a/b
If a random rotation, the first buckle and the second time is completely independent, so the probability is b/n
1#include <cstdio>2#include <cstring>3 4 Const intMAXN = -+Ten;5 CharS[MAXN];6 7 intMain ()8 {9 //freopen ("In.txt", "R", stdin);Ten One while(SCANF ("%s", s) = =1) A { - intL =strlen (s); -S[L] = s[0]; the intZero =0, Doublezero =0; - for(inti =0; I < L; ++i) - { - if(S[i] = ='0') +zero++; - if(S[i] = ='0'&& s[i+1] =='0') +doublezero++; A } at intD = Doublezero * L-zero *Zero; - if(D >0) -Puts"SHOOT"); - Else if(D <0) -Puts"ROTATE"); - Else inPuts"EQUAL"); - } to + return 0; -}
code June
UVa 1636 (probability) headshot