日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

UVa11021

發(fā)布時間:2023/12/10 编程问答 27 豆豆
生活随笔 收集整理的這篇文章主要介紹了 UVa11021 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

11021 Tribbles
GRAVITATION, n.
“The tendency of all bodies to approach one another with a strength
proportion to the quantity of matter they contain – the quantity of
matter they contain being ascertained by the strength of their tendency
to approach one another. This is a lovely and edifying illustration of
how science, having made A the proof of B, makes B the proof of A.”
Ambrose Bierce
You have a population of k Tribbles. This particular species of Tribbles live for exactly one day and
then die. Just before death, a single Tribble has the probability Pi of giving birth to i more Tribbles.
What is the probability that after m generations, every Tribble will be dead?
Input
The first line of input gives the number of cases, N. N test cases follow. Each one starts with a line
containing n (1 n 1000), k (0 k 1000) and m (0 m 1000). The next n lines will give the
probabilities P0; P1; : : : ; Pn?1.
Output
For each test case, output one line containing ‘Case #x:’ followed by the answer, correct up to an
absolute or relative error of 10?6.
Sample Input
43
1 1
0.33
0.34
0.33
3 1 2
0.33
0.34
0.33
3 1 2
0.5
0.0
0.5
4 2 2
0.5
0.0
0.0
0.5
Universidad de Valladolid OJ: 11021 – Tribbles 2/2
Sample Output
Case #1: 0.3300000
Case #2: 0.4781370
Case #3: 0.6250000
Case #4: 0.3164062

題意:

?????? 有k只麻球,每只活一天就會死亡,臨時前可能會產(chǎn)生一些新的麻球。產(chǎn)生i(0<=i<=n)個麻球的概率是Pi。給定m,求m天(或者不足m天)之后所有麻球都死亡的概率。

?

分析:

?????? 由于每只麻球的后代獨立存活,只需要求出一開始只有1只麻球,m天會全部死亡的概率f(m)。由全概率公式:

?????? f(i) = P0 + P1 * f(i - 1) + P2 * f(i - 1) ^ 2 + … + Pn * f(i - 1) ^ n。

最終答案為f(m) ^ k。

1 #include <cstdio> 2 #include <cmath> 3 const int maxn = 1000; 4 const int maxm = 1000; 5 int n,k,m; 6 double P[maxn + 1],f[maxn + 1];// f[i]表示麻球在i天后全死亡的概率 7 int main(){ 8 int T; scanf("%d",&T); 9 int kase = 0; 10 while(T--){ 11 scanf("%d%d%d",&n,&k,&m); 12 for(int i = 0 ; i < n ; i++) scanf("%lf",&P[i]); 13 f[0] = 0,f[1] = P[0]; 14 for(int i = 2 ; i <= m ; i++){ 15 f[i] = 0; 16 for(int j = 0 ; j < n ; j++) 17 f[i] += P[j] * pow(f[i - 1],j); 18 } 19 printf("Case #%d: %.7lf\n",++kase,pow(f[m],k)); 20 } 21 return 0; 22 } View Code

?

轉(zhuǎn)載于:https://www.cnblogs.com/cyb123456/p/5815637.html

總結(jié)

以上是生活随笔為你收集整理的UVa11021的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。