zoukankan      html  css  js  c++  java
  • LightOJ1317 _6thweek contest problem_A

    Throwing balls into the baskets:

    题目大意:

    有N个人,M个篮框,K个回合,每个回合每个人可以投一颗球,每个人的命中率都是相同的P,问K回合后,投中的球的期望数是多少

    分析:

    每个人的投篮都是一个独立的事件,互不影响,所以每回合投中的球的期望数是相同的 
    只需求得一回合的期望再乘上K就为答案。

    然后代码如下:

     1 #include<iostream>
     2 #include<cstdio>
     3 using namespace std;
     4 double ans,p;
     5 int n,m,k;
     6 int c[20][20];
     7 
     8 void init()
     9 {
    10     c[1][1]=c[1][0]=1;
    11     for(int i=2;i<20;i++)
    12     {
    13         c[i][i]=c[i][0]=1;
    14         for(int j=1;j<i;j++)
    15             c[i][j]=c[i-1][j]+c[i-1][j-1];
    16     }
    17 }
    18 double count(int j)
    19 {
    20     double t=1.0;
    21     for(int i=0;i<j;i++)
    22         t*=p;
    23     for(int i=0;i<n-j;i++)
    24         t*=(1.0-p);
    25     return t*j*c[n][j];
    26 }
    27 int main()
    28 {
    29     int test,cas=1;
    30     scanf("%d",&test);
    31     init();
    32     while(test--)
    33     {
    34         scanf("%d%d%d%lf",&n,&m,&k,&p);
    35         ans=0.0;
    36         for(int i=0;i<=n;i++)
    37             ans+=count(i);
    38 
    39     printf("Case %d: %.7lf
    ",cas++,ans*k);
    40     }
    41     return 0;
    42 }
    View Code
  • 相关阅读:
    3.5.3 数据排序;重复数值、缺失值处理
    3.5.1 pandas基础
    3.3 numpy
    数据准备和特征工程
    2.4函数
    2.3语句与控制流
    2.2数据结构与序列
    2.1Python基础知识
    五、MySQL安装
    四、Hadoop HA 集群搭建
  • 原文地址:https://www.cnblogs.com/x512149882/p/4750584.html
Copyright © 2011-2022 走看看