zoukankan      html  css  js  c++  java
  • FZU2132

    Problem Description

    LQX在做作业时遇到一个难题不会做,请你帮她计算一下:在N个独立地分布于0和1之间的随机变量排为非递减顺序之后,这些变量中第M个小于等于x的概率是多少?

    Input

    第一行一个整数T(T<=1000),表示有T组数据。

    每组数据一行,依次是N M x(1<=M<=N<30, 0<x<1),以空格隔开。

    Output

    每组数据对应一行输出,即概率是多少,四舍五入保留4位小数。

    Sample Input

    31 1 0.32 1 0.52 2 0.8

    Sample Output

    0.30000.75000.6400
     
     
     
    难道最近在复习概率论的缘故??上次在FZU月赛上就出了2题,这道题目到最后死活也咳不出来,今天周赛终于来了复习的灵感!!!
     
    按照题目要求,不断循环求符合要求的概率,累加
     
     
    #include<iostream>
    #include<string.h>
    #include<stdio.h>
    #include<ctype.h>
    #include<algorithm>
    #include<stack>
    #include<queue>
    #include<set>
    #include<math.h>
    #include<vector>
    #include<map>
    #include<deque>
    #include<list>
    using namespace std;
    double f(int n)
    {
        double s= 1;
        for(int i = 1; i <= n; i++)
            s *= i;
        return s;
    }
    double c(int m,int n)
    {
        double w=f(m)/(f(n)*f(m-n));
        return w;
    }
    int main()
    {
        int t;
        int n,m;
        double x;
        scanf("%d",&t);
        while(t--)
        {
            double p=0;
            scanf("%d%d%lf",&n,&m,&x);
            for(int i=m; i<=n; i++)
            {
                p+=c(n,i)*pow(x,i)*pow(1-x,n-i);
            }
            printf("%.4f
    ",p);
        }
        return 0;
    }
    

  • 相关阅读:
    PHP面试系列之Linux(一) ----- Linux基础
    Redis入门(一)---安装
    获取主机ip地址
    Ubuntu安装Apache
    Ubuntu安装MySQL/MariaDB
    Ubuntu安装PHP7
    shell一次性执行多条命令
    将宿主主机上的目录挂载到Docker中
    bind 仿造 重写bind
    echars 饼状图 轮循 水平翻转
  • 原文地址:https://www.cnblogs.com/fuhaots2009/p/3476490.html
Copyright © 2011-2022 走看看