codeforces-312B Archer(数学)

本文介绍了一个简单的概率射击游戏问题,两名射手轮流射击目标,先射中者获胜。文章提供了计算射手SmallR胜率的C++代码,并解释了如何通过迭代方法求解此问题,确保计算精度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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.

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 exceed 10 - 6.

Examples

Input
1 2 1 2

Output
0.666666666667
据说这是一道概率水题,但是是我的盲点,体现的思想可能是事件发生次数越多就越精确(maybe0.0)。确定精度是让前后两个答案相减即可。

#include <bits/stdc++.h>
using namespace std;
int main()
{
    double a,b,c,d;
    cin>>a>>b>>c>>d;
    double p=a/b,q=c/d;
    double ans=p,pre=0,temp=1;
    while(abs(ans-pre)>1e-9)
    {
        pre=ans;
        temp*=(1-p)*(1-q);
        ans+=temp*p;
    }
    cout<<fixed<<setprecision(10)<<ans<<endl;
    return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值