H. Coin Question II Time limit:1000 ms Case time limit:1000 ms Memory limit:65536kb64-bit integer Io format: % LLD Java class name: mainsubmit status PID: 29064 font size: + -
Chubby has an asymmetric coin. If you throw the coin once, the probability of positive orientation is P, and the probability of positive orientation is 1-P. Now, Chubby wants to use this coin to produce a decision with equal probability (50% to 50% ). Of course, only one throw is not acceptable. The strategy of Chubby is as follows: every decision requires two coins. If both are positive or reverse, the decision is made again, if it is positive for the first time, it means throwing the front. If it is positive for the first time, it is regarded as throwing the back. In this way, we can get a fair decision.
Now the question is, how many times does the chubby average get a decision for a given P (that is, no more )?
Input
The first line contains an integer n (n <= 100), indicating the number of test data.
Next, there will be n rows, one test data per row, and a three-digit floating point number P (0 <p <1 ).
Output
Output a row for each test data, including a floating-point number, indicating the average number of times a small fat coin is thrown.
Returns two decimal places.
Sample Input
30.5000.8000.300
Sample output
4.006.254.76
#include<stdio.h>int main(){ double ex,p; int n; scanf("%d",&n); while(n--) { scanf("%lf",&p); ex=1.0/p+1.0/(1-p); printf("%.2lf\n",ex); }}
H. Coin Question II