Archer 【CF--312B】
2015-12-06 20:32
411 查看
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
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>
相关文章推荐
- setAttribute这个方法
- <黑马程序员> 第七篇:IO
- Java运用JSON实现后台与前端分工合作(代码实例)
- EM算法与高斯混合分布
- toArray()与toArray(T [] a)的区别
- 学习数据结构有用吗?
- 卫星资源分配
- 项目开发计划
- 模板模式与原型模式
- Xcode消除编译器警告
- Basic--Java基本语法
- android5.0自带兼容控件__CardView
- 6大设计原则(一)---单一职责原则
- project euler 60
- Linux下端口被占用解决
- 转义字符序列及其功能
- 第三个Sprint冲刺第二天
- Linux设置交换分区swap
- Hibernate框架学习(一 )
- COCOS2D-3.9 Configuration 接口分析