博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
HDU 5810 Balls and Boxes 数学
阅读量:6252 次
发布时间:2019-06-22

本文共 1120 字,大约阅读时间需要 3 分钟。

Balls and Boxes

题目连接:

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

转载地址:http://nlysa.baihongyu.com/

你可能感兴趣的文章
064:ORM查询条件详解-in和关联模型查询
查看>>
实现不在栈中产生对象
查看>>
申请企业级IDP、真机调试、游戏接入GameCenter 指南、游戏接入OpenFeint指南
查看>>
maven 遇见的问题
查看>>
关于JVM内存模型,GC策略以及类加载器的思考
查看>>
ethereum/EIPs-100 挖矿难度计算
查看>>
ethereumjs/ethereumjs-blockchain-2-test
查看>>
centos7安装登录图形界面
查看>>
Css布局系列-float 浮动
查看>>
lowbit
查看>>
【总结】四月份找实习总结
查看>>
【JS】Intermediate7:jQuery:DOM API
查看>>
iphone-common-codes-ccteam源代码 CCUIApplication.h
查看>>
10,object类
查看>>
团队第一次作业
查看>>
Kooboo CMS 无聊随笔(2)
查看>>
static 和 global
查看>>
Ubuntu12.04安装及环境配置总结
查看>>
费马小定理,欧拉函数
查看>>
浮点型数据的比较
查看>>