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. C#的Struct

  2. [转载]AngularJS 开发者最常犯的 10 个错误

    http://www.oschina.net/translate/top-10-mistakes-angularjs-developers-make

  3. zabbix user parameters和Loadable modules的使用方法介绍

    目录 需求 实现 原理 前端配置 后端配置 shell实现 python实现 C实现 需求: 采集主机的-/+ buffers/cache  free的数据 实现: 采集/proc/meminfo中的 ...

  4. 【腾讯云】自己搭建的腾讯云服务器JavaEE环境

    0.安装SSH登录 1.生成公钥对 ssh-keygen -t rsa -P '' -P表示密码,-P '' 就表示空密码,也可以不用-P参数,这样就要三车回车,用-P就一次回车.它在/home/ch ...

  5. RESTful 个人理解总结【转】

    转自:http://www.cnblogs.com/wang-yaz/p/9237981.html 一.什么是RESTful 面向资源 简单的说:RESTful是一种架构的规范与约束.原则,符合这种规 ...

  6. 【mac】7z 终端命令行

    链接:http://www.2cto.com/os/201410/341079.html 7z指令 7z是7zip压缩工具的常用压缩文件格式.7zip是一个开源的压缩工具,软件本身十分小巧,功能强大, ...

  7. SpringBoot 构建RestFul API 含单元测试

    相关博文: 从消费者角度评估RestFul的意义 SpringBoot 构建RestFul API 含单元测试 首先,回顾并详细说明一下在快速入门中使用的  @Controller .  @RestC ...

  8. C# 特性(Attribute)详细介绍

    1.什么是Atrribute 首先,我们肯定Attribute是一个类,下面是msdn文档对它的描述:公共语言运行时允许你添加类似关键字的描述声明,叫做attributes, 它对程序中的元素进行标注 ...

  9. Java 基本语法---流程控制

    Java 基本语法---流程控制 0. 概述 三大流程控制语句:顺序.选择.循环. 选择结构: if 结构,if - else结构: 多重 if - else 语句 ; 嵌套 if - else 语句 ...

  10. 测试开发之Django——No3.Django中的试图(views)

    说到views,我们先来说django中执行的一个顺序. 我们打开一个django中配置的页面,之后的执行是有这么几个步骤: 1.系统配置的urls中寻找是否配置了这个地址: 2.如果已经配置了这个地 ...