Question Translation
You have a gun (revolver). You have loaded some bullets randomly. You have fired a gun and found that there are no bullets. You hope that there will be no bullets for the next one, should you just open a gun (output "shoot"), or turn it around first, and then open a gun (output "Rotate ")? If the probability of a gun without a bullet is equal in two cases, the output is "equal ". Note: here, the conversion is not to the next position, but to random, that is, to transfer the equi probability to every position of the bullet sequence. The bullet sequence in the pistol can be seen as a binary sequence, such as 0011. Before the first shot, it must be in the position 1 or 2 (because your first shot was not shot ), therefore, the gun is located at the position 2 or 3. If the gun is shot at this time, half of the probability cannot be shot. In addition, the bullet sequence is a circular sequence, that is, 0011 is equivalent to 1001;
Data ensures that the length of the bullet sequence is 2 ~ 100
Example 0011 0111 000111 output sample equal rotate shoot
Description
PDF
Input/Output Format
Input Format:
Output Format:
Input and Output sample
No test point
Question
For direct shooting, remember how many $0 $, and then the last one of the $0 $ is $1 $, the probability of failure is $(01 Quantity)/(0 quantity) $.
The probability of conversion is $ (number of 0)/(sequence length) $
Then compare it.
I am too lazy to handle the precision. I used cross-multiplication.
1 qwerta 2 uva1636 headshot accepted 3 code C ++, 0.46kb 4 submission time 17:13:47 5 elapsed time/memory 0 ms, 0kb 6 7 # include <iostream> 8 # include <cstdio> 9 Using namespace STD; 10 string s; 11 int main () 12 {13 while (CIN> S) 14 {15 int Zr = 0; // The number of records 0 16 for (INT I = 0; I <S. length (); ++ I) 17 if (s [I] = '0') Zr ++; 18 // shoot19 int DY = 0; // record 01 count 20 for (INT I = 0; I <S. length ()-1; ++ I) 21 if (s [I] = '0' & S [I + 1] = '1') dy ++; 22 int n = S. length (); 23 if (s [n-1] = '0' & S [0] = '1') dy ++; // do not forget that it is a circular 24 // 25 int y = S. length ()-Zr; // calculate the number of 1: 26 if (dy * n <Zr * Y) {cout <"shoot" <Endl ;} // If dy/Zr <Y/n27 else if (dy * n = Zr * Y) {cout <"equal" <Endl ;} 28 else cout <"Rotate" <Endl; 29} 30 return 0; 31}
"Uva1636" headshot (Probability