bnu29064--Coin Water Title II —————— "event probability"

Source: Internet
Author: User

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"

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.