HDU 1099.Lottery【数学题,求期望】【12月31】
来源:互联网 发布:linux隐藏windows分区 编辑:程序博客网 时间:2024/05/24 23:14
Lottery
Problem Description
Eddy's company publishes a kind of lottery.This set of lottery which are numbered 1 to n, and a set of one of each is required for a prize .With one number per lottery, how many lottery on average are required to make a complete set of n coupons?
Input
Input consists of a sequence of lines each containing a single positive integer n, 1<=n<=22, giving the size of the set of coupons.
Output
For each input line, output the average number of lottery required to collect the complete set of n coupons. If the answer is an integer number, output the number. If the answer is not integer, then output the integer part of the answer followed by a space and then by the proper fraction in the format shown below. The fractional part should be irreducible. There should be no trailing spaces in any line of ouput.
Sample Input
2517
Sample Output
3 511 -- 12 34046358 ------ 720720
题目的大概意思是说一套彩票有编号1到n共n种,张数不限,问你平均买多少张能把编号为1到n的n中彩票全买下来,也就是求期望。
举个例子,当n=5时,第一张有用的概率为1,买一张就行了,第二张有用的概率为4/5,所以买5/4张彩票能买上对你有用的,一次类推,sum=1+5/4+5/3+5/2+5/1=11…5/12
AC代码如下:
#include<iostream>#include<cstdio>using namespace std;long long gcd(long long a, long long b){ long long r; while(b > 0) { r = a % b; a = b; b = r; } return a;}int main(){ int n; while(cin >> n) { unsigned long long y = 1; unsigned long long x = 0; for(int i = 1;i <= n; ++i) { x = y+i*x; y *= i; long long GCD = gcd(x, y); x /= GCD; y /= GCD; } long long GCD = gcd(n, y); y /= GCD; n /= GCD; x *= n; //格式控制太操蛋! if(x%y == 0) cout << x/y << endl; else { if(x/y > 9) cout <<" "; cout <<" "<< x%y <<endl; cout << x/y <<" "; long long zz = y; while(zz) { cout <<"-"; zz /= 10; } cout << endl; if(x/y > 9) cout <<" "; cout <<" "<< y <<endl; } } return 0;}
0 0
- HDU 1099.Lottery【数学题,求期望】【12月31】
- 数学题(2)——求数学期望
- hdu 4465 求期望
- hdoj 1099 Lottery(期望)
- hdu 1724数学题 辛普森公式求积分
- HDU/HDOJ 1099 Lottery
- hdu 1099 lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- hdu 1099 Lottery
- 【数学】 HDU 1099 Lottery
- HDU ACM 1099 Lottery
- HDU 1099 Lottery 乐透彩
- HDOJ HDU 1099 Lottery
- hdu 4405 概率dp 求期望
- hdu 4035概率dp 求期望
- HDU 4035 dp求期望 好题
- php读取html文件(或php文件)的方法
- 利用fitnesse实现api接口自动化测试
- 安卓常用工具及网址
- 我们通常会采用attr方法来给元素设置属性,其实attr方法同样是能够得到元素对应的属性的
- 自己收集了几个android 开源框架连接
- HDU 1099.Lottery【数学题,求期望】【12月31】
- springmvc 3+ hibernate 3遇到的问题记
- Linux下Python安装
- Java EE+axis2搭建webservice服务(二)
- 欢迎使用CSDN-markdown编辑器
- 一种更清晰的Android架构
- Android调用系统相机与图库
- iOS提高开发效率的方法和工具
- UNIX环境高级编程——进程(一)