UVa11427 Expect the Expected

时间:2023-03-09 04:14:07
UVa11427 Expect the Expected

数学期望 概率递推

每一天的概率都是独立且相同的。可以先推出每天打i盘赢j盘的概率f[i][j]

f[i][j]=f[i-1][j]*(1-p) + f[i-1][j-1]*p

    输          赢

设此人打一天胜率不满足要求的概率为p

那么打一天的概率是1*p

打两天的概率是1*p*(p^2)

以此类推

----

题解待施工

学自http://www.cnblogs.com/neopenx/p/4282768.html

----

WA点:

  1、a和b用double存,可能引起了精度误差。

  2、输出没换行

 /*by SilverN*/
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<vector>
using namespace std;
const int mxn=;
int n;
double f[mxn][mxn];
int main(){
int T;int i,j,a,b,cas=;
scanf("%d",&T);
double p;
while(T--){
memset(f,,sizeof f);
scanf("%d/%d%d",&a,&b,&n);
p=(double)a/b;
f[][]=;
f[][]=;
for(i=;i<=n;i++){
f[i][]=f[i-][]*(-p);
for(j=;j*b<=i*a;j++){
f[i][j]=f[i-][j]*(-p)+f[i-][j-]*p;
}
}
double res=0.0;
for(i=;i<=n;i++)res+=f[n][i];//
double ans=/res;
printf("Case #%d: %d\n",++cas,(int)ans);
}
return ;
}