CF 312B(Archer-等比数列极限求和)

本文介绍了一个射手对决中获胜概率的计算方法。通过给定两个射手每次射击命中目标的概率,利用等比数列无限求和公式计算出了先手射手赢得比赛的概率。

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

B. Archer
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
1 2 1 2
output
0.666666666667


等比数列无限求和公式 a+ap+ap^2+...    0<p<1   -->     S=a/(1-p)



#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<cctype>
using namespace std;
#define For(i,n) for(int i=1;i<=n;i++)
#define Rep(i,n) for(int i=0;i<n;i++)
#define Fork(i,k,n) for(int i=k;i<=n;i++)
#define ForD(i,n) for(int i=n;i;i--)
#define Forp(x) for(int p=pre[x];p;p=next[p])
#define RepD(i,n) for(int i=n;i>=0;i--)
int main()
{
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	double a,b,c,d;
	cin>>a>>b>>c>>d;
	printf("%.12lf\n",a/b/(1-(1-a/b)*(1-c/d)));
	
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值