UVa 10056 What is the Probability ?
解題:注意是做到<1e-7
Code:
Code:
1
#include<stdio.h>
2 #include<stdlib.h>
3 #include<algorithm>
4 #include<iostream>
5 using
namespace std;
6 int main()
7 {
8 int cas;
9 cin>>cas;
10 while(cas--)
11 {
12 double n,p,m;
13 cin>>n>>p>>m;
14 double time=m-1,ans=0,pre=0;
15 ans=pow(1-p,time)*p;
16 while(ans-pre>1e-7)
17 {
18
time+=n;
19 pre=ans;
20 ans+=pow(1-p,time)*p;
21 }
22 printf("%.4f\n",ans);
23 }
24 return 0;
25 }
留言
張貼留言