1 /** 2 对于大数的很好的应用,,缩小放大,,保持精度 3 **/ 4 #include <iostream> 5 #include <cmath> 6 #include <algorithm> 7 #include <cstdio> 8 using namespace std; 9 10 int main() 11 { 12 double n,p; 13 int cnt =1; 14 while(cin>>n>>p){ 15 double p1 = log(p+0.0); 16 double p2 = log(1-p+0.0); 17 double s1 = (n+1)*p1; 18 double s2 = (n+1)*p2; 19 double ans =0,c=0; 20 for(int i=0;i<n;i++){ 21 ans += (exp(c+s1)+exp(c+s2))*(n-i); 22 c += log(n+1+i+0.0)-log(i+1+0.0); 23 s1 += p2; 24 s2 += p1; 25 } 26 printf("Case %d: %.6lf ",cnt++,ans); 27 } 28 return 0; 29 }