zoukankan      html  css  js  c++  java
  • HDU 5810 Balls and Boxes

    Balls and Boxes

    Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 291    Accepted Submission(s): 213


    Problem Description
    Mr. Chopsticks is interested in random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner that each ball has equal probability of going to each boxes. After the experiment, he calculated the statistical variance V as
    V=mi=1(XiX¯)2m

    where Xi is the number of balls in the ith box, and X¯ is the average number of balls in a box.
    Your task is to find out the expected value of V.
     
    Input
    The input contains multiple test cases. Each case contains two integers n and m (1 <= n, m <= 1000 000 000) in a line.
    The input is terminated by n = m = 0.
     
    Output
    For each case, output the result as A/B in a line, where A/B should be an irreducible fraction. Let B=1 if the result is an integer.
     
    Sample Input
    2
    1 2
    2 0
    0
     
    Sample Output
    0/1 1/2
    Hint
    In the second sample, there are four possible outcomes, two outcomes with V = 0 and two outcomes with V = 1.
     

    球落入每个盒子的概率是1/m

    概率不变,n个球  可以当作n次实验   可用二项分布做

    方差 D(x)=n*p*q

    p=1/m q=1-1/m

    带入可得  D(x)=n*(m-1)/(m*m)

    方差的期望就是 方差的均值 而每个盒子的方差是相等的,所以期望的值就是方差的值了

    /* ***********************************************
    Author        :guanjun
    Created Time  :2016/8/10 12:46:03
    File Name     :hdu5810.cpp
    ************************************************ */
    #include <iostream>
    #include <cstring>
    #include <cstdlib>
    #include <stdio.h>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <iomanip>
    #include <list>
    #include <deque>
    #include <stack>
    #define ull unsigned long long
    #define ll long long
    #define mod 90001
    #define INF 0x3f3f3f3f
    #define maxn 10010
    #define cle(a) memset(a,0,sizeof(a))
    const ull inf = 1LL << 61;
    const double eps=1e-5;
    using namespace std;
    priority_queue<int,vector<int>,greater<int> >pq;
    struct Node{
        int x,y;
    };
    struct cmp{
        bool operator()(Node a,Node b){
            if(a.x==b.x) return a.y> b.y;
            return a.x>b.x;
        }
    };
    
    bool cmp(int a,int b){
        return a>b;
    }
    int main()
    {
        #ifndef ONLINE_JUDGE
        //freopen("in.txt","r",stdin);
        #endif
        //freopen("out.txt","w",stdout);
        ll n,m;
        while(scanf("%lld %lld",&n,&m)!=EOF){
            if(n==0&&m==0)break;
            ll a=n*(m-1);
            ll b=m*m;
            ll k=__gcd(a,b);
            printf("%lld/%lld
    ",a/k,b/k);
        }
        return 0;
    }
  • 相关阅读:
    浅析JNI
    网易云音乐歌词下载器
    如何用一个SQL“搞挂”一个服务模块
    SpingBoot 1.5.2,MultipartFile保存图片时的不稳定异常(好像和内置tomcat有关)
    double 去除小数点后的0
    项目中时间处理----今天:时分(10:15),昨天/前天:(昨天/前天),除此之外的本周(星期几),再往前年.月.日(2017.06.15)
    SpringMvc 静态内部类 封装请求数据
    jsp页面 ajax提交数组 到struts2的action
    Struts2 s:if test判断时遇到的问题
    Struts2中 iterator隔行变色
  • 原文地址:https://www.cnblogs.com/pk28/p/5756502.html
Copyright © 2011-2022 走看看