H. Coin Question II

Source: Internet
Author: User
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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.