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. 字典树(Tire)模板

    #include<stdio.h> #include<string.h> #include<stdlib.h> struct node { node *ne[]; ...

  2. Java虚拟机详解03----常用JVM配置参数

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  3. MySQL数据库学习笔记(九)----JDBC的ResultSet接口(查询操作)、PreparedStatement接口重构增删改查(含SQL注入的解释)

    [声明] 欢迎转载,但请保留文章原始出处→_→ 生命壹号:http://www.cnblogs.com/smyhvae/ 文章来源:http://www.cnblogs.com/smyhvae/p/4 ...

  4. Properties集合的练习

    1.更改文件中的数据,特定键的值: 需求:我有一个文本文件(user.txt),我知道数据是键值对形式的,但是不知道内容是什么. 请写一个程序判断是否有"lisi"这样的键存在,如 ...

  5. LSB最低有效位隐写入门

    LSB也就是最低有效位 (Least Significant Bit) 被替换成传递的信息字节.对原图影响很小. 这题可以算是隐写工具[wbStego]的使用入门练习题吧. 第一步,告诉你工具是支持在 ...

  6. java的IO操作之--RandomAccessFile

    目标: 1)掌握RandomAccessFile类的作用. 2)用RandomAccessFile读取指定位置的数据. 具体内容 RandomAccessFile类的主要功能是完成随机读取功能,可以读 ...

  7. gridpanel分组汇总

    [ExtJS5学习笔记]第三十节 sencha extjs 5表格gridpanel分组汇总 2015-05-31     86 本文地址:http://blog.csdn.net/sushengmi ...

  8. WPF学习笔记:MVVM模式下,ViewModel如何关闭View?

    原文:http://blog.csdn.net/leftfist/article/details/32349731 矫枉过正,从一个极端走向另一个极端.MVVM模式,View只负责呈现,虽然也有后台代 ...

  9. Oracle Update

    在表的更新操作中,在很多情况下需要在表达式中引用要更新的表以外的数据.象sql server提供了update的from 子句,可以将要更新的表与其它的数据源连接起来.虽然只能对一个表进行更新,但是通 ...

  10. Kinect for Windows SDK开发初体验(一)环境配置

    1.开发环境需求 (1).硬件需求 a.需要拥有双核,2.66GHz以上的CPU. b.显卡支持Microsoft DirectX 9.0c; c.2GB的内存 d.Kinect for Window ...