Headshottime limit:1000msmemory limit:65536kbthis problem'll be judged onPKU. Original id:3869
64-bit integer IO format: %lld Java class name: Main You had a revolver gun with a cylinder that had n chambers. Chambers is located in a circle on a cylinder. Each chamber can is empty or can contain a round. One chamber is aligned with the gun ' s barrel. When trigger of the gun was pulled, the gun's cylinder rotates, aligning the next chamber with the barrel, hammer strikes t He round, making a shot by firing a bullet through the barrel. If The chamber is empty when the hammer strikes it, then there was no shot but just a "click".
You are found a use for this gun. You is playing Russian roulette with your friend. Your friend loads rounds into some chambers, randomly rotates the cylinder, aligning a random chamber with a gun ' s barrel, Puts the gun to his head and pulls the trigger. You hear "click" and nothing else-the chamber is empty and the gun did not shoot.
Now it's your turn to put the gun to your head and pull the trigger. You have a choice. You can either pulling the trigger right away or you can randomly rotate the gun's cylinder and then pulling the trigger. What should choose to maximize the chances of your survival?InputThe input file contains a single line with a string of n digits "0" and "1" (2 <= n <= 100). This line of digits represents the pattern of rounds, were loaded into the gun ' s chambers. "0" represent an empty chamber, "1" represent a loaded one. In this representation, when cylinder rotates before a shot, the next chamber to the right gets aligned with the barrel fo R a shot. Since The Chambers is actually located on a circle and the first chamber in this string follows the last one. There is at the least one "0" in this string.OutputWrite to the output file one of the following words (without quotes):
"SHOOT"-if pulling the trigger right away makes you less likely to being actually shot in the head with the bullet (more Li Kely that the chamber would be empty).
"ROTATE"-if randomly rotating the cylinder before pulling the trigger makes you less likely to being actually shot in the H EAD with the bullet (more likely, that the chamber would be is empty).
"EQUAL"-if both of the above choices is EQUAL in terms of probability of being shot.
Sample Input
Sample input #1:0011Sample input #2:0111Sample input #3:000111
Sample Output
Sample output #1: equalsample output #2: rotatesample output #3: SHOOT
SourceNortheastern Europe 2009
Problem solving: English reading problem .... Conditional probability what, meaning is currently 0, then the probability of 00 is how much, if the choice of rotation, then the rotation of the probability of 0 is how much, and then compare the probability size can be
1#include <cstdio>2#include <cstring>3 using namespacestd;4 Const intMAXN = +;5 CharSTR[MAXN];6 intMain () {7 while(~SCANF ("%s", str)) {8 intlen = strlen (str), a =0, B =0, C =0;9 for(inti =0; i < Len; ++i)Ten if(Str[i] = ='0') { One if(Str[(i+1)%len] = ='0') a++; A Else if(Str[(i+1)%len] = ='1') b++; -}ElseC++; - if(Len*a = = (len-c) * (A + B)) puts ("EQUAL"); the Else if(Len*a < (len-c) * (A + B)) puts ("ROTATE"); - ElsePuts"SHOOT"); - } - return 0; +}
View Code
POJ 3869 headshot