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

题意:给出两个弓箭手的射中目标的概率(分数),两人轮流射击,求第一位弓箭手赢的概率(小数)

分析:第一位弓箭手赢,那么第一次就射中或者,第一次不中而第二个弓箭手也不中,第二次中,……

p=a/b为第一位射中的概率,q=c/d为第二位射中的概率。

题目要求误差小于1e-6,刚开始我的代码是下面这样

#include<stdio.h>
int main(){
double a,b,c,d,ans,u;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
ans=;u=;
while(u*a/b>=1e-){//改成-7、-8也会WA,-9可过
u*=(-a/b)*(-c/d);
ans+=u;
}
printf("%lf\n",ans*a/b);
return ;
}

因为当u*a/b<1e-6时ans继续加下去,可能比当前ans大不止1e-6,因为后面加了好几次;正确的方法是用等比数列求和公式

s=(1-qn)/(1-q),当n趋于无穷时,因为0<q<1,所以s=1/(1-q)

q=(1-a/b)*(1-c/d),ans=s*a/b.

#include<stdio.h>
int main(){
double a,b,c,d,ans,u;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
ans=/(-(-a/b)*(-c/d));
printf("%.12lf\n",ans*a/b);
return ;
}

进行化简一下得到

#include<stdio.h>
int main(){
double a,b,c,d,ans,u;
scanf("%lf%lf%lf%lf",&a,&b,&c,&d);
printf("%.12lf\n",a*d/(a*d+b*c-a*c));
return ;
}

【CodeForces 312B】BUPT 2015 newbie practice #3A Archer的更多相关文章

  1. 【CodeForces 605A】BUPT 2015 newbie practice #2 div2-E - Sorting Railway Cars

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/E Description An infinitely lon ...

  2. 【UVALive 3905】BUPT 2015 newbie practice #2 div2-D-3905 - Meteor

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/D The famous Korean internet co ...

  3. 【HDU 4925】BUPT 2015 newbie practice #2 div2-C-HDU 4925 Apple Tree

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/C Description I’ve bought an or ...

  4. 【UVA 401】BUPT 2015 newbie practice #2 div2-B-Palindromes

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/B A regular palindrome is a str ...

  5. 【UVA 11078】BUPT 2015 newbie practice #2 div2-A -Open Credit System

    http://acm.hust.edu.cn/vjudge/contest/view.action?cid=102419#problem/A In an open credit system, the ...

  6. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  7. 【最大流】ECNA 2015 F Transportation Delegation (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N(N<=600)个点,每个点有个名字Si,R(R<=200)个生产商在R个点上,F(F<= ...

  8. 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空 ...

  9. 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N个点M条无向边,(N<=100,M<=N(N-1)/2),起始感染源S,时间T(T<10) ...

随机推荐

  1. 2014 UESTC 暑前集训队内赛(2) 部分解题报告

    B.Cuckoo for Hashing 模拟题. 代码: #include <iostream> #include <cstdio> #include <cstring ...

  2. JavaWeb学习之Servlet(二)----Servlet的生命周期、继承结构、修改Servlet模板

    [声明] 欢迎转载,但请保留文章原始出处→_→ 文章来源:http://www.cnblogs.com/smyhvae/p/4140466.html 一.http协议回顾: 在上一篇文章中:JavaW ...

  3. QTP和WinRunner区别

    QTP,全称为Quick Test Professional,它与WinRunner同为MI公司开发的功能强大的功能测试工具.从时间上来看,WinRunner在1995年便已经推出,远早于QTP,而Q ...

  4. [转] 值得推荐的C/C++框架和库

    http://www.cppblog.com/merlinfang/archive/2014/12/26/209311.aspx

  5. 认识实验室信息管理系统(LIMS)

    在当今互联网如日中天的大环境下,各种伴随着互联网的产物如p2p,o2o在如火如荼的进行着,吸引了大量的开发人员都涌向了这个行业,所有的技术似乎都在围绕着互联网发展,传统行业软件开发的人气和关注度就相形 ...

  6. JavaScript实现级联下拉框

    <!DOCTYPE html> <html> <head> <meta name="author" content="Yeeku ...

  7. 06Spring_使用注解配置bean对象

    Spring注解开发需要jar包 和 xml开发 一样的 ! 第一步: 新建项目, 导入jar包(就是前一篇文章里面的那几个核心jar包) 第二步: 在需要spring创建对象类上面 添加@Compo ...

  8. 配置错误定义了重复的“system.web.extensions/scripting/scriptResourceHandler” 解决办法

    今天遇到了这个问题, 电脑系统:vs2010 win7系统 iis7 我运行在iis中配置的那个网站后,报错:错误代码 0x800700b7 配置错误定义了重复的“system.web.extensi ...

  9. An Introduction to Interactive Programming in Python (Part 1) -- Week 2_1 练习

    # Practice Exercises for Functions # Solve each of the practice exercises below. # 1.Write a Python ...

  10. freemarker语法简介

    ftl是一种模板标记语言,用于渲染数据,输入html结构.语法简介如下: ${book.name} ${book.name?if_exists} //值是否存在 ${book.name??} //值是 ...