UVa 10169 Urn-ball Probabilities ! (概率)

262 篇文章 1 订阅
8 篇文章 0 订阅

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取对数即可。


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


完整代码:

/*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;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值