zoukankan      html  css  js  c++  java
  • Tribles(概率)

    Description
     

    Problem A
    Tribbles
    Input: Standard Input

    Output: Standard Output

    GRAVITATIONn.
    "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 kTribbles. 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, everyTribble will be dead?

    Input
    The first line of input gives the number of cases, NN 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 P0P1, ...,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

    Sample Output

    4 
    3 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
    Case #1: 0.3300000 
    Case #2: 0.4781370 
    Case #3: 0.6250000 
    Case #4: 0.3164062 
    
                
              

    题意:有K只麻球,每只只活一天,临死前会产仔,产i只小麻球的 概率为pi,问m天后所有麻球全部死亡的概率;

    思路:因为每只麻球都是相互独立的,所以只需求刚开始只有一只麻球,m天后其后代全部死亡的概率f[m],然后k只麻球最后全部死亡的概率就是 pow(f[m],k);

    对于一只麻球,m天全死亡包含第一天、第二天、、、、、第m天死亡事件,因此一只麻球第i天死亡的概率f[i] = p0 + p1*f[i-1] + p2*f[i-2]^2+.......+ pn-1*f[i-1]^(n-1);

     1 #include<stdio.h>
     2 #include<math.h>
     3 #include<string.h>
     4 int main()
     5 {
     6     int test;
     7     scanf("%d",&test);
     8     for(int item = 1; item <= test; item++)
     9     {
    10         int n,k,m;
    11         double p[1100],f[1100];
    12         scanf("%d %d %d",&n,&k,&m);
    13         for(int i = 0; i < n; i++)
    14             scanf("%lf",&p[i]);
    15 
    16         f[0] = 0;
    17         f[1] = p[0];
    18         for(int i = 2; i <= m; i++)
    19         {
    20             f[i] = 0;
    21             for(int j = 0; j < n; j++)
    22                 f[i] += p[j] * pow(f[i-1],j);
    23         }
    24         printf("Case #%d: %.7lf
    ",item,pow(f[m],k));
    25     }
    26     return 0;
    27 }
    View Code
  • 相关阅读:
    用SSMS连接Azure Sql Database 与连接本地库的一些操作区别
    python_高级进阶(3)线程
    python_高级进阶(2)进程与并发
    python_高级进阶(1)进程与并发
    python网络(2)_Udp协议
    python网络(2)_Tcp协议
    python网络(1)_认知
    python异常处理
    python面向对象(5)__特殊双下方法
    python面向对象(4)_细分类的组成成员
  • 原文地址:https://www.cnblogs.com/LK1994/p/3405302.html
Copyright © 2011-2022 走看看