Balls and Boxes

题目连接:

http://acm.hdu.edu.cn/showproblem.php?pid=5810

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(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.

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

题意

有n个球,m个盒子,问你n个球放在盒子里面的方差的期望是多少。

题解:

正解是数学,但是我们是打表找规律……

答案 n(m-1)/m^2

代码

#include<bits/stdc++.h>
using namespace std; int main(){
long long n,m;
while(cin>>n>>m){
if(n==0&&m==0)break;
long long a=n*(m-1),b=m*m;
long long tmp = __gcd(a,b);
cout<<a/tmp<<"/"<<b/tmp<<endl;
}
}

HDU 5810 Balls and Boxes 数学的更多相关文章

  1. HDU 5810 Balls and Boxes(盒子与球)

     Balls and Boxes(盒子与球) Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/O ...

  2. HDU 5810 Balls and Boxes (找规律)

    Balls and Boxes 题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5810 Description Mr. Chopsticks is i ...

  3. hdu 5810 Balls and Boxes 二项分布

    Balls and Boxes Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  4. HDU 5810 Balls and Boxes ——(数学,概率,方差)

    官方题解看不太懂,参考了一些人的博客以后自己证明如下: 其中D(X)和E(X)的公式如下(参考自百度百科): 其中 p = 1 / m .(这是每一个单独事件发生的概率期望,在这里单独事件指的是一个球 ...

  5. HDU 5810 Balls and Boxes

    n*(m-1)/(m*m) #pragma comment(linker, "/STACK:1024000000,1024000000") #include<cstdio&g ...

  6. hdu 5810:Balls and Boxes(期望)

    题目链接 这题似乎就是纯概率论.. E(V)=D(X_i)=npq (p=1/m,p+q=1) #include<bits/stdc++.h> using namespace std; t ...

  7. HDU 4611 Balls Rearrangement (数学-思维逻辑题)

    题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=4611 题意:给你一个N.A.B,要你求 AC代码: #include <iostream> ...

  8. Codeforces Round #158 (Div. 2) C. Balls and Boxes 模拟

    C. Balls and Boxes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  9. HDU5810 Balls and Boxes

    Balls and Boxes                                                                            Time Limi ...

随机推荐

  1. Codeforces 338 D. GCD Table

    http://codeforces.com/problemset/problem/338/D 题意: 有一张n*m的表格,其中第i行第j列的数为gcd(i,j) 给出k个数 问在这张表格中是否 有某一 ...

  2. LaTeX文章结构

    %导言 %\documentclass{article} %ctexbook \documentclass{ctexbook} \title{\heiti 监督学习} % 黑体 \author{\ka ...

  3. 在C#中使用.NET SDK创建控制

    下载示例工程 - 8 Kb 介绍 在这篇教程中,我将使用.NET架构创建一个简单的时钟控制示例,这个控制是一个显示当前时间的时钟,我将指导读者实现秒针并显示钟点数.文章加亮处是创建这个控制的关键点,读 ...

  4. mount过程分析之一(基于3.16.3内核)【转】

    转自:https://blog.csdn.net/zr_lang/article/details/39963253 一直想写有些关于文件系统的博文,但是由于近一年来实在太忙,所以没有时间写.前几日赶上 ...

  5. MySQL用户密码过期登陆报错ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement.

    今天接到主从复制失败告警,查看MySQL,发现MySQL能够登陆但是执行命令报错, ERROR 1820 (HY000): You must reset your password using ALT ...

  6. Ansible Tower系列 四(使用tower执行一个命令)【转】

    在主机清单页面中,选择一个主机清单,进入后,选择hosts里的主机 Paste_Image.png 点击 RUN COMMANDS MODULE 选择 commandARGUMENTS 填写 ifco ...

  7. linux下查看各硬件型号

    查看主板型号 # dmidecode |grep -A 8 "System Information"System Information 上网查DELL CS24-TY,找到说主板 ...

  8. Ubuntu+Nginx+uWSGI+Flask应用

    Ubuntu 18.04,Nginx 1.14.0,uWSGI 2.0.17.1,Flask 1.0.2,Python 3.6.5, 多日未更新博客,就是在忙着把自己的Flask应用在Ubuntu上运 ...

  9. Java abstract 关键字

    abstract是声明抽象类和抽象方法的关键字 包含抽象方法的类叫抽象类,如果一个类中包含一个或多个抽象方法,该类必须被限定为抽象的,否则编译器会报错,抽象类不可创建对象,创建抽象类的对象编译器会报错 ...

  10. 阿里云服务器配置nginx和PHP

    1. 安装及启动nginx 输入yum install nginx命令进行nginx的安装,当需要确认时输入”y“确认. yum install nginx 安装完成后,输入service nginx ...