HDU 5810 Balls and Boxes two distributions

Source: Internet
Author: User

Balls and Boxes

Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): 260 Accepted Submission (s): 187


problem DescriptionMr. Chopsticks is interested in the random phenomena, and he conducts an experiment to study randomness. In the experiment, he throws n balls into m boxes in such a manner so each ball have equal probability of going to each B Oxes. After the experiment, he calculated the statistical variance V as
V=∑mi=1 (xi−x¯) 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.
 

InputThe input contains multiple test cases. Each case contains the integers n and m (1 <= N, M <=) in a line.
The input is terminated by n = m = 0. 

Outputfor each case, output the result as A/b in A line, where A/b should is an irreducible fraction. Let b=1 if the result was an integer. 

Sample Input2 0 

Sample Output0/11/2Hintin the second sample, there is four possible outcomes, and the other outcomes with V = 0 and both outcomes with V = 1. 

AuthorSysu 

Sourcemulti-university Training Contest 7 

recommendwange2014 | We have carefully selected several similar problems for you: 5820 5819 5817 5816 5815 Test Instructions: give you n ball, m box, the probability that each ball falls into each box is so possible, the expectation of variance is obtained.
 #include <iostream> #include <cstdio> #include <cstdlib># Include <cmath> #include <map> #include <vector> #include <queue> #include <cstring># Include <string> #include <algorithm>using namespace std;typedef long long ll;typedef unsigned long long ull; #define MM (A, B) memset (A,b,sizeof (a)), #define INF 0x7f7f7f7f#define for (I,N) for (int i=1;i<=n;i++) #define CT Continue; #define PF printf#define SC scanfconst int mod=1000000007;const int n=1e3+10;ll gcd (ll a,ll b) {if (b==0) retur    n A; else return gcd (b,a%b);}    int main () {ll n,m; while (~SCANF ("%lld%lld", &n,&m) && (n| |      m) {ll fenzi=n* (m-1), fenmu=m*m;          while (1) {ll k=gcd (FENZI,FENMU);          if (k==1) break;      Fenzi/=k;fenmu/=k;    } printf ("%lld/%lld\n", FENZI,FENMU); } return 0;} 

 Analysis: The game is a feeling of what distribution, but learn a lot and forget, finally Baidu a bit, only to find that can be two distribution to do;

For each box, the probability of each ball falling into it is p=1/m;

So a total of n balls P (x=k) =c (n,k) *p^k* (1-p) ^ (n-k), apparently two distributions;

Two-item distribution mathematical expectation E (x) =NP (n is the number of experiments, p is the probability of each test ball falling into the box);

Variance d (x) =NP (1-p)

In this subject D (x) =n/m* (1-1/m) =n* (m-1)/(m^2);

Then because each box is equal, the variance is the degree of confusion that describes the data, so the variance of multiple equal boxes is the same as a single box variance

HDU 5810 Balls and Boxes two distributions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.