zoj 3551 Bloodsucker
2011-11-10 10:53
190 查看
In0thday,therearen-1peopleand1bloodsucker.Everyday,twoandonlytwoofthemmeet.Nothingwillhappeniftheyareofthesamespecies,thatis,apeoplemeetsapeopleorabloodsuckermeetsabloodsucker.Otherwise,peoplemaybe
transformedintobloodsuckerwithprobabilityp.Soonerorlater(Ddays),allpeoplewillbeturnedintobloodsucker.CalculatethemathematicalexpectationofD.
point),separatedbyspaces.
[/code]
transformedintobloodsuckerwithprobabilityp.Soonerorlater(Ddays),allpeoplewillbeturnedintobloodsucker.CalculatethemathematicalexpectationofD.
Input
Thenumberoftestcases(T,T≤100)isgiveninthefirstlineoftheinput.Eachcaseconsistsofanintegernandafloatnumberp(1≤n<100000,0<p≤1,accurateto3digitsafterdecimalpoint),separatedbyspaces.
Output
Foreachcase,youshouldoutputtheexpectation(3digitsafterthedecimalpoint)inasingleline.SampleInput
1
21
SampleOutput
1.000
一道概率题,可以这样考虑:
根据题意,每天只能增加一个Bloodsucker,也就是说n-1个正常人是一个接着一个变成Bloodsucker的,那么所有正常人变成Bloodsucker的天数期望等于所有正常人变成Bloodsucker的天数期望之和。考虑n-1个正常人中第i个变成Bloodsucker的正常人的转变概率为:
P[i]=i*(n-i)/(n*(n-1)/2)
则天数期望为(直接从概率的定义考虑):
D[i]=1/P[i]
于是:
[align=center]D=sum(D[i])[/align][align=center][/align][align=center][/align][align=center][/align]
代码如下
#include<stdio.h>
intmain(){
intT;
intn;
doublep;
scanf("%d",&T);
while(T--){
scanf("%d%lf",&n,&p);
doubleres=0;
doubletmp=n*0.5*(n-1)/p;
inti;
for(i=1;i<=(n-1)/2;i++){
res+=tmp/i/(n-i);
}
res*=2;
res+=(n%2==0)?(4*tmp/n/n):0;
printf("%.3lf\n",res);
}
return0;
}
[/code]
原文链接http://blog.chinaunix.net/space.php?uid=26372629&do=blog&id=2996052
相关文章推荐
- ZOJ 3551 Bloodsucker
- ZOJ 3551 Bloodsucker
- ZOJ 3551 Bloodsucker [概率DP]
- ZOJ 3551 Bloodsucker
- ZOJ 3551 Bloodsucker 概率DP
- ZOJ 3551 Bloodsucker (概率DP)
- ZOJ 3551 Bloodsucker 概率DP
- ZOJ_3551_Bloodsucker
- ZOJ 3551 Bloodsucker (概率DP)
- ZOJ 3551 Bloodsucker 题解
- zoj 3551 Bloodsucker 概率DP
- ZOJ 3551 Bloodsucker(概率)
- zoj 3551 Bloodsucker (概率dp)
- ZOJ 3551 Bloodsucker(概率DP)
- [zoj 3551]Bloodsucker[概率DP]
- ZOJ 3551 Bloodsucker(概率dp啊 )
- zoj 3551 Bloodsucker 概率DP
- zoj 3551
- zoj 3351 Bloodsucker(概率 dp)
- zoj 3551 简单 概论dp