uva 11673 Garbage Remembering Exam (概率)
题目链接: http://vjudge.net/problem/viewProblem.action?id=42000
该过程为随即过程,因此总期望值等于个单词对应的期望值,即它们wasted的概率
1 #include <stdio.h> 2 #include <cstring> 3 #include <cstdlib> 4 #include <algorithm> 5 #include <cmath> 6 7 using namespace std; 8 #define lson o<<1 9 #define rson o<<1|1 10 #define max(a,b) (a)>(b)?(a):(b) 11 #define min(a,b) (a)<(b)?(a):(b) 12 #define INF 200000000 13 #define N 100010 14 typedef long long ll; 15 long double lg[N]; 16 17 void init (){ 18 lg[1]=0; 19 for(int i=2;i<N;i++){ 20 lg[i]=(long double)log(i)+lg[i-1]; 21 } 22 } 23 int main(){ 24 int n,k,cs=1; 25 init(); 26 while(scanf("%d%d",&n,&k) && n){ 27 long double p,ans=0; 28 int up,down,put=2*k; 29 if(2*k>n-1)put=n-1; 30 long double l0=lg[n-1]-lg[n-1-put]; 31 for(int i=1;i<=n;i++){ 32 up=max(i-1-k,0); 33 down=max(n-i-k,0); 34 if(up+down>=put)p=exp(lg[up+down]-lg[up+down-put]-l0); 35 else p=0; 36 ans+=1-p; 37 } 38 printf("Case %d: %.4lf\n",cs++,(double)ans); 39 } 40 return 0; 41 }