| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1726 人关注过本帖
标题:一道CF算法题:通过对有限次抛掷两枚硬币的结果分析得出一枚正面朝上的概率 ...
只看楼主 加入收藏
yiyue123
Rank: 2
等 级:论坛游民
威 望:1
帖 子:78
专家分:78
注 册:2018-6-18
结帖率:100%
收藏
 问题点数:0 回复次数:0 
一道CF算法题:通过对有限次抛掷两枚硬币的结果分析得出一枚正面朝上的概率大于另一枚的概率的概率
发下原题和本人渣翻
498. Coins
                                  498.硬币
Time limit per test: 0.75 second(s)
每次测试时间限定:0.75s
Memory limit: 262144 kilobytes
限定内存:262144 kilobytes
input: standard
output: standard
标准输入输出

Andrew has just made a breakthrough in gambling: he has invented a way to make coins which have probability p of landing heads-up and 1 - p of landing tails-up when tossed, where p is some number between 0 and 1.
Andrew近来在赌博上取得重大突破:他发明了一种方法来赚取硬币,就是那种在投掷时有p的概率正面朝上和1-p的概率反面朝上的硬币,p是某个在0和1之间的数。
He can't, however, control the number p itself, and creates coins with any p from 0 to 1 with equal probability.
然而,他并不能控制概率p本身,并等可能的创造概率p从0到1变化的硬币。
 That is, the value of p is a random value uniformly distributed on  .
也就是说,p的值是一个在0到1之间随机分布的数。
Andrew has generated two coins independently.
Andrew已经互相独立地准备了两枚硬币。
One with probability p and another with probability q of landing heads-up.
一枚朝上的概率为p,另一枚为q。
Random values p and q are both uniformly distributed on  and are independent.
随机值p和q都分布在0至1之间并相互独立。
Of course, neither Andrew nor we know the numbers p and q, we can only try to guess them using our observations.
自然,不论是Andrew还是我们都不知道p和q的值,我们只能通过我们的观察来进行猜测。
The observations are the following: the first coin was tossed n1 times, and m1 of them landed heads-up. The second coin was tossed n2 times, and m2 of them landed heads-up. Your task is to compute the probability that p < q.
观测方法如下:第一枚硬币被投掷n1次,并有m1次正面朝上。第二枚硬币被投掷n2次,并有m2次正面朝上。你的任务是计算出p<q的概率。
Input
The first line of the input file contains one integer T ( ) — the number of test cases to solve. Each of the following T lines contains 4 integers each: n1, m1, n2, m2. 1 ≤ n1, n2 ≤ 1000, 0 ≤ m1, m2 ≤ 50, 0 ≤ m1 ≤ n1, 0 ≤ m2 ≤ n2.
第一行输入包含一个整数T ( ),即测试用例的数,在T行下的每一行包含4个整数,分别为:n1,m1,n2,m2. 1 ≤ n1, n2 ≤ 1000, 0 ≤ m1, m2 ≤ 50, 0 ≤ m1 ≤ n1, 0 ≤ m2 ≤ n2.

Output
For each test case output one line with a floating-point number, the probability of p < q. Your answer will be considered correct if it is within 10-4 of the right answer.
每次测试用例输出一个浮点数,即p<q的概率。你的结果将被认为正确如果它与正确答案相差不超过10-4
Example(s)
sample input    sample output
4
2 1 4 3     0.7142857142
8 4 16 8    0.5000000000
2 0 6 1     0.5333333333
2 0 2 1     0.8000000000







搜索更多相关主题的帖子: 概率 and number the with 
2018-08-16 23:40
快速回复:一道CF算法题:通过对有限次抛掷两枚硬币的结果分析得出一枚正面朝上的 ...
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.030591 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved