UVa 10169 Urn-ball Probabilities !:概率

10169 - Urn-ball Probabilities !

Time limit: 3.000 seconds

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1110

看输出要求:The floating-point number indicates the probability that you have picked up two red balls in at least one of your pick-ups and the second integer denotes how many consecutive zeros are there after decimal point in the probability value that all of your pick ups has both balls as red.

第一个值是在N次摸球中,至少有一次从两个瓮中都取出红球的概率;第二个值是在N次摸球都是红球的概率中,在小数点后有多少个连续的0。

思路:

1. 全概率公式。如果前面摸了球,后面不管摸不摸到红球,概率都一样;前面如果没摸到球(1-P(n-1)),那么就要乘上这次摸到球的概率1/ (n*(n+1))

所以P(n) = P(n-1) + (1-P(n-1)) / (n*(n+1))

我们可以事先打表计算P(n)。

2. 每次都摸到红球的话,概率为(1*1/2)*(1/2*1/3)*...*(1/n*1/(n+1)),算连续0取对数即可。

求递推式的生成函数?(待研究,坑)

完整代码:

01./*0.108s*/
02.
03.#include<cstdio>
04.#include<cmath>
05.const long long N = 1000001;
06.
07.double a[N], b[N];
08.
09.int main()
10.{
11.    int n, i;
12.    double ans = 0.0, count = 0.0, tmp;
13.    for (i = 1; i < N; ++i)
14.    {
15.        tmp = (double)i * (i + 1);
16.        ans += (1 - ans) / tmp;
17.        count += log10(tmp);
18.        a[i] = ans, b[i] = count;
19.    }
20.    while (~scanf("%d", &n))
21.        printf("%.6f %d\n", a[n], (int)b[n]);
22.    return 0;
23.}

查看本栏目更多精彩内容:http://www.bianceng.cnhttp://www.bianceng.cn/Programming/sjjg/

以上是小编为您精心准备的的内容,在的博客、问答、公众号、人物、课程等栏目也有的相关内容,欢迎继续使用右上角搜索按钮进行搜索count
, double
, 概率
, 前面
, 概率论
, tmp
全概率
urn ball、10169358a8945f5c、en10169、probabilities、prior probabilities,以便于您获取更多的相关知识。

时间: 2024-10-31 19:43:43

UVa 10169 Urn-ball Probabilities !:概率的相关文章

算法题:UVA 10169

Problem B Urn-ball Probabilities! Input: standard input Output: standard output Time Limit: 3 seconds Assume that you have two urns before you. Initially, one urn has one ball and the other urn has two balls and exactly one ball in each urn is red. A

UVa 10759 Dice Throwing:概率DP

10759 - Dice Throwing Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=1700 n common cubic dice are thrown. What is the probability that the sum of all thr

UVa 10491 Cows and Cars:概率及广义三门问题

10491 - Cows and Cars Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1432 In television contests, participants are often asked to choose one from a set

UVa 10056 What is the Probability ? (概率&amp;amp;有一个陷阱)

10056 - What is the Probability ? Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=997 Probability has always been an integrated part of computer algorith

UVa 10387 Billiard:计算几何&amp;amp;反射

10387 - Billiard Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=101&page=show_problem&problem=1328 In a billiard table with horizontal side a inches and vertical side b inches, a bal

HDU 4254 A Famous Game (概率&amp;amp;组合数学公式)

A Famous Game http://acm.hdu.edu.cn/showproblem.php?pid=4254 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Problem Description Mr. B and Mr. M like to play with balls. They have many balls colored in blue and red. F

UVa 10277 Boastin&#039; Red Socks (枚举)

10277 - Boastin' Red Socks Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=1218 You have a drawer that is full of two kinds of socks: red and black. You

UVa 11181 Probability|Given:DFS及贝叶斯公式

11181 - Probability|Given Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=115&page=show_problem&problem=2122 思路: 拿样例一的"三选二"为例: 分母怎么求?P=买*买*不买+买*不买*买+不买*买*买=0.092,这是三个人中恰有两个人

UVa 12004 Bubble Sort:想法题

http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=3155 枚举交换次数算期望太麻烦,不妨换个思路:对于任意一对数字,它们之间发生交换的概率和不交换的概率是相等的,那这对数字提供的期望值就为1/2.总共有C(n,2)对数字,所以最终的期望值就为n*(n-1)/4 完整代码: 01./*0.015s*/ 02. 03.#include<cs