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. Linux命令(二)关机重启

  2. Sublime Text 3 绿色汉化版 x64

    之前做了<Sublime Text 2 绿色汉化版 x64>,这些天抽空做了下 ST3 的汉化.. 果然我没有任何理由爱上 ST3,不仅pojie麻烦,而且汉化更麻烦,菜单字符长度做了限制 ...

  3. 20155225 2016-2017-2 《Java程序设计》第八周学习总结

    20155225 2016-2017-2 <Java程序设计>第八周学习总结 教材学习内容总结 通用API 日志API 国际化基础 规则表达式 JDK8增强功能 教材学习中的问题和解决过程 ...

  4. 【转】把Git Repository建到U盘上去

    CHENYILONG Blog 把Git Repository建到U盘上去 转 把Git Repository建到U盘上去 Git很火.原因有三: 它是大神Linus Torvalds的作品,天然地具 ...

  5. (AC自动机)C - 病毒侵袭持续中

    题目链接:https://cn.vjudge.net/contest/280743#problem/C 题目大意:中文题 具体思路:首先取ascii码0-130是肯定不行的了,会超时.然后就开始简化, ...

  6. redhat7配置本地yum源

    1.首先是要有一个iso文件,并将这个文件挂载到某个目录 挂载: 配置: 检验: yum list 现在你就可以在没有网的情况下,安装软件了~~~

  7. linux笔记_day11_shell编程

    1.条件测试类型: 整数测试 字符测试 文件测试 条件测试的表达式: [ expression ] 必须有空格 [[ expression ]] test expression 整数比较 : -eq  ...

  8. JS windows.open打开窗口并居中

    function openWin() {            var url='Add.aspx';                             //转向网页的地址;           ...

  9. windows 2008 启用.NET Framework 3.5

    Win2008下已经集成了.NET 3.5.1 framework,需要在管理界面打开! 方法和步骤是: 服务器管理器 -> 功能 -> 添加功能 然后在“选择功能”界面勾选“.NET F ...

  10. FreeMarker使用小记(HelloWorld)

    FreeMarker是开源的模板框架.对于它的介绍网上已经很多了.详情可参考主页:http://www.freemarker.org/ 现在我们就开始我们的FreeMarker版的Hello Worl ...