Archer 【CF--312B】

来源:互联网 发布:知行理工密码 编辑:程序博客网 时间:2024/06/11 17:10

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 for SmallR while for Zanoes. The one who shoots in the target first should be the winner.

Output the probability that SmallR will win the match.


题意:SmallR和Zanoes都是射箭运动员。SmallR准备与Zanoes举行一场射箭比赛,SmallR第一个发剪,然后两人轮流进行射箭,SmallR投中靶子的概率为a/b,Zanoes投中靶子的概率为c/d,谁第一个投中靶子谁就获胜,求SmallR赢得比赛的概率。


思路:由概率知识知,p=a/b+a/b*(1-a/b)*(1-c/d)+a/b*((1-a/b)^2)*((1-c/d)^2)+....+a/b*((1-a/b)^n)*((1-c/d)^n),当n很大时,p=a/b*(1/(1-(1-a/b)*(1-c/d))).


Input

A single line contains four integers.

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 exceed10 - 6.

Sample Input

1 2 1 2

Sample Output

0.666666666667

<span style="font-family:KaiTi_GB2312;font-size:18px;">#include <cstdio>#include <cstring>#include <algorithm>using namespace std;int main(){int a,b,c,d;while(~scanf("%d %d %d %d",&a,&b,&c,&d)){double s=(a*1.0/b);double ss=(1-(a*1.0/b))*(1-(c*1.0/d));printf("%.12f\n",s*1.0/(1-ss));}return 0;}</span>


0 0