Time Limit: 20 Sec

Memory Limit: 256 MB

题目连接

http://codeforces.com/contest/312/problem/B

Description

SmallR is an archer. SmallR is taking a match of archer with Zanoes. They try to shoot in the target in turns, and SmallR shoots first. The probability of shooting the target each time is Codeforces Round #185 (Div. 2) B. Archer 水题 for SmallR while Codeforces Round #185 (Div. 2) B. Archer 水题 for Zanoes. The one who shoots in the target first should be the winner.

Output the probability that SmallR will win the match.

Input

A single line contains four integers Codeforces Round #185 (Div. 2) B. Archer 水题.

Output

Print a single real number, the probability that SmallR will win the match.

The answer will be considered correct if the absolute or relative error doesn't exceed 10 - 6.

Sample Input

1 2 1 2

Sample Output

0.666666666667

HINT

 

题意

第一个人有a/b的概率射中靶子,第二个人有c/d的概率射中靶子,两个人轮流射

然后问你有多大的概率第二个人最先射中靶子

题解:

水题啦,很容易推公式,发现是一个等比数列,然后求和就好了

也可以不求和,直接暴力for也行

代码:

#include<iostream>
#include<stdio.h>
#include<math.h>
using namespace std;


int main()
{
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    double p1 = a/b,p2 = c/d;
    double ans = 0;
    double p = 1;
    for(int i=0;i<10000;i++)
    {
        ans += p*(1-p1)*p2;
        p = p * (1-p1) * (1-p2);
    }
    printf("%.10f\n",1-ans);
}

 

相关文章: