Coin water problem iitime limit:1000msmemory limit:65536kb64-bit integer IO format:%lld Java class name: Main Submit Status pid:29064
Chubby has a coin with a positive and negative face. If you toss this coin, the probability of its facing upward is p, and the probability of the opposite facing up is 1-p. Now, Chubby wants to use this coin to produce equal probability decisions (50% to 50%). Of course, it's not possible to just toss it once. The strategy for chubby is this: every decision needs to be tossed two times, if it is either positive or negative, then make a decision again; if it is a positive one, then if the first is facing upward, then it is said that if the first is a face-up, then it is considered to be the opposite. In this way, a fair decision can be made.
The question now is, given a p, how many times will the fat average be thrown to get a decision (i.e. no more throwing)?
Input
The first line contains an integer N (n<=100) that represents the number of test data.
Next consists of n rows, one test data per line, including a 3-bit floating point P (0<p<1).
Output
For each test data, the output line, including a floating-point number, represents the average count of the small-fat coin toss.
The result retains two decimal places.
Sample Input
30.5000.8000.300
Sample Output
4.006.254.76
#include <bits/stdc++.h>using namespace Std;int main () { int n; scanf ("%d", &n); while (n--) { double p; scanf ("%lf", &p); Double ans=1.0/(1.0-p*p-(1-p) * (1-p)); printf ("%.2lf\n", 2*ans); } return 0;}
#include <bits/stdc++.h>using namespace Std;int main () { int n; scanf ("%d", &n); while (n--) { double p; scanf ("%lf", &p); Double ans=1.0/p+1.0/(1.0-p); printf ("%.2lf\n", ans); } return 0;}
bnu29064--Coin Water Title II —————— "event probability"