• 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;
    }
  • 相关阅读:
    无题
    静心
    随笔
    skynet1.0阅读笔记2_skynet的消息投递skynet.call
    skynet1.0阅读笔记_skynet的启动
    Mysql: Connect/C++ 使用过程中发现返回 std::string 造成的内存泄露
    MySql C++调用库Connector/c++编译 和 接口封装【三】Connector/c++ 使用总结及封装
    MySql: ”Commands out of sync“Error (Connect/C++)
    Connector/c++ 查询Mysql,出现 can't fetch because not on result set 错误
    mysql 修改密码
  • 原文地址:https://www.cnblogs.com/pk28/p/5756502.html
Copyright © 2020-2023  润新知