10169 - Urn-ball Probabilities !
Time limit: 3.000 seconds
看输出要求: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取对数即可。
求递推式的生成函数?(待研究,坑)
完整代码:
/*0.108s*/
#include<cstdio>
#include<cmath>
const long long N = 1000001;
double a[N], b[N];
int main()
{
int n, i;
double ans = 0.0, count = 0.0, tmp;
for (i = 1; i < N; ++i)
{
tmp = (double)i * (i + 1);
ans += (1 - ans) / tmp;
count += log10(tmp);
a[i] = ans, b[i] = count;
}
while (~scanf("%d", &n))
printf("%.6f %d\n", a[n], (int)b[n]);
return 0;
}

本文详细介绍了解决Urn-ball概率问题的全概率公式应用,包括递推式生成函数的构建,以及如何通过代码实现计算至少一次从两个瓮中取出红球的概率,以及在N次摸球中全部为红球的概率,特别关注于小数点后连续零的数量。
2772

被折叠的 条评论
为什么被折叠?



