• uva 11021 Tribbles


    解题思路:设一开始只有 1 只麻雀,i 天后全部死亡的概率为 f(i). 则有:f(0)=0, f(1)=p0 , f(i)=p0 + p1 · f(i-1) + p2 · f(i-1)2 + ··· + pn-1 · f(i-1)n-1 . 则本题答案为 f(m)k .

      1 ///////////////////////////////////////////////////////////////////////////
      2 //problem_id: uva 11021
      3 //user_id: SCNU20102200088
      4 ///////////////////////////////////////////////////////////////////////////
      5 
      6 #include <algorithm>
      7 #include <iostream>
      8 #include <iterator>
      9 #include <iomanip>
     10 #include <cstring>
     11 #include <cstdlib>
     12 #include <string>
     13 #include <vector>
     14 #include <cstdio>
     15 #include <cctype>
     16 #include <cmath>
     17 #include <queue>
     18 #include <stack>
     19 #include <list>
     20 #include <set>
     21 #include <map>
     22 using namespace std;
     23 
     24 ///////////////////////////////////////////////////////////////////////////
     25 #pragma comment(linker,"/STACK:1024000000,1024000000")
     26 
     27 #define lson l,m,rt<<1
     28 #define rson m+1,r,rt<<1|1
     29 ///////////////////////////////////////////////////////////////////////////
     30 
     31 ///////////////////////////////////////////////////////////////////////////
     32 const double EPS=1e-8;
     33 const double PI=acos(-1.0);
     34 
     35 const int x4[]={-1,0,1,0};
     36 const int y4[]={0,1,0,-1};
     37 const int x8[]={-1,-1,0,1,1,1,0,-1};
     38 const int y8[]={0,1,1,1,0,-1,-1,-1};
     39 ///////////////////////////////////////////////////////////////////////////
     40 
     41 ///////////////////////////////////////////////////////////////////////////
     42 typedef long long LL;
     43 
     44 typedef int T;
     45 T max(T a,T b){ return a>b? a:b; }
     46 T min(T a,T b){ return a<b? a:b; }
     47 T gcd(T a,T b){ return b==0? a:gcd(b,a%b); }
     48 T lcm(T a,T b){ return a/gcd(a,b)*b; }
     49 ///////////////////////////////////////////////////////////////////////////
     50 
     51 ///////////////////////////////////////////////////////////////////////////
     52 //Add Code:
     53 ///////////////////////////////////////////////////////////////////////////
     54 
     55 int main(){
     56     ///////////////////////////////////////////////////////////////////////
     57     //Add Code:
     58     int Case,n,k,m,i,j,t;
     59     double p[1005],f[1005];
     60     scanf("%d",&Case);
     61     for(i=1;i<=Case;i++){
     62         scanf("%d%d%d",&n,&k,&m);
     63         for(j=0;j<n;j++) scanf("%lf",&p[j]);
     64         memset(f,0,sizeof(f));
     65         f[0]=0,f[1]=p[0];
     66         for(j=2;j<=m;j++){
     67             double temp=1;
     68             for(t=0;t<n;t++){
     69                 f[j]+=p[t]*temp;
     70                 temp*=f[j-1];
     71             }
     72         }
     73         printf("Case #%d: %.8lf
    ",i,pow(f[m],k));
     74     }
     75     ///////////////////////////////////////////////////////////////////////
     76     return 0;
     77 }
     78 
     79 ///////////////////////////////////////////////////////////////////////////
     80 /*
     81 Testcase:
     82 Input:
     83 4
     84 3 1 1
     85 0.33
     86 0.34
     87 0.33
     88 3 1 2
     89 0.33
     90 0.34
     91 0.33
     92 3 1 2
     93 0.5
     94 0.0
     95 0.5
     96 4 2 2
     97 0.5
     98 0.0
     99 0.0
    100 0.5
    101 Output:
    102 Case #1: 0.3300000
    103 Case #2: 0.4781370
    104 Case #3: 0.6250000
    105 Case #4: 0.3164062
    106 */
    107 ///////////////////////////////////////////////////////////////////////////
  • 相关阅读:
    Docker Harbor安装和使用
    k8s部署使用Jenkins
    K8S之Deployment
    K8S之StatefulSet
    Gitlab数据迁移和版本升级
    centos7 编译安装git工具
    K8S之secret
    SonarQube的安装和使用
    Jenkins常用构建工具
    el-upload上传/预览时dialog宽自适应
  • 原文地址:https://www.cnblogs.com/linqiuwei/p/3325011.html
Copyright © 2020-2023  润新知