HDU 1099 Lottery (求数学期望)
传送门:
http://acm.hdu.edu.cn/showproblem.php?pid=1099
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4319 Accepted Submission(s): 1921
5
17
5
11 --
12
340463
58 ------
720720
假如发行2张,第一次买的序号是1,第二次买中剩下那张的概率是1/2,所以要买两张才能买到第二张,所以要买3张才能才能集齐。
假如发行3张,第一次发的序号是1,要买1张,第二次买中剩下的两张之一的概率是2/3,所以要买3/2张,第三次买剩中最后一张的概率是1/3,所以要买3张,所以要买5+1/2张。
假如发行n张,第一次买中没买过的概率是1,第二次是n-1/n,第三次是n-2/n,第n次是1/n,
而对应需要买的张数是第一次买1张,第二次买n/n-1张,第三次买n/n-2,第n次买n张,所以求的是n/n,n/n-1,……1/n的和。
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define max_v 25
struct node
{
LL molecule;//分子
LL Denominator;//分母
};
LL gcd(LL a,LL b)//最大公约数
{
if(b==)
return a;
return gcd(b,a%b);
}
LL lcm(LL a,LL b)//最小公倍数
{
return a/gcd(a,b)*b;
}
LL numlen(LL x)//数字长度
{
LL c=;
while(x)
{
x=x/;
c++;
}
return c;
}
node f(int n)
{
node p;
p.molecule=;
p.Denominator=;
if(n==)
return p;
for(LL i=;i<=n;i++)
{
LL x=lcm(i,p.Denominator);
p.molecule=p.molecule*(x/p.Denominator)+(x/i);
p.Denominator=x;
LL y=gcd(p.Denominator,p.molecule);
p.Denominator=p.Denominator/y;
p.molecule=p.molecule/y;
// printf("fz=%I64d fm=%I64d 最小公倍数=%I64d\n",p.molecule,p.Denominator,x);
}
p.molecule=p.molecule*n;
LL y=gcd(p.Denominator,p.molecule);
p.Denominator=p.Denominator/y;
p.molecule=p.molecule/y; return p;
}
int main()
{
int n;
while(~scanf("%d",&n))
{
node p=f(n);
if(p.molecule%p.Denominator==)
printf("%I64d\n",p.molecule/p.Denominator);
else
{
LL x=p.molecule/p.Denominator;
p.molecule=p.molecule-(x*p.Denominator);
LL y=gcd(p.Denominator,p.molecule);
p.Denominator=p.Denominator/y;
p.molecule=p.molecule/y; int l1=numlen(x);
int l2=numlen(p.Denominator);
for(int i=;i<=l1;i++)
printf(" "); printf("%I64d\n",p.molecule);
printf("%I64d ",x);
for(int i=;i<=l2;i++)
printf("-");
printf("\n");
for(int i=;i<=l1;i++)
printf(" ");
printf("%I64d\n",p.Denominator);
}
}
return ;
}
HDU 1099 Lottery (求数学期望)的更多相关文章
- hdu 1099 Lottery
这是我第一次写博客,作为一个ACMer,经常进别人的博客,所以自己也想写写博客. HDU 1099 Lottery Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 4465 Candy (数学期望)
题意:有两个盒子各有n个糖(n<=2*105),每天随机选1个(概率分别为p,1-p),然后吃掉一颗糖.直到有一天打开盒子一看,这个盒子没有糖了.输入n,p,求此时另一个盒子里糖的个数的数学期望 ...
- HDU - 1099 - Lottery - 概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...
- HDU 4336 Card Collector 数学期望(容斥原理)
题目地址: http://acm.hdu.edu.cn/showproblem.php?pid=4336 题意简单,直接用容斥原理即可 AC代码: #include <iostream> ...
- [CF912D]Fishes - 求数学期望,乱搞
D. Fishes time limit per test 1 second memory limit per test 256 megabytes input standard input outp ...
- uva 10828 高斯消元求数学期望
Back to Kernighan-RitchieInput: Standard Input Output: Standard Output You must have heard the name ...
- [2013山东ACM]省赛 The number of steps (可能DP,数学期望)
The number of steps nid=24#time" style="padding-bottom:0px; margin:0px; padding-left:0px; ...
- hdu 3232 Crossing Rivers(期望 + 数学推导 + 分类讨论,水题不水)
Problem Description You live in a village but work in another village. You decided to follow the s ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
随机推荐
- Jenkins+Postman+Newma+Xmysql之API全自动化测试
第一章 前期准备:各种安装配置介绍 ①Postman安装及使用 ②Newman 安装及使用 ③Xmysql 安装及使用 ④Jenkins安装及配置 1.postman 安装及使用 1.1.postma ...
- The Java serialization algorithm revealed---reference
Serialization is the process of saving an object's state to a sequence of bytes; deserialization is ...
- mysql 查两个表相同的值
比如一个数据库 表A和表B 都有一个username字段, 现查出与表A中username值相同的表B的username和password数据 select B.username,B.password ...
- Advanced .NET Debugging: Managed Heap and Garbage Collection(转载,托管堆查内存碎片问题解决思路)
原文地址:http://www.informit.com/articles/article.aspx?p=1409801&seqNum=4 Debugging Managed Heap Fra ...
- IntelliJ IDEA 2017.2 下载和破解方法
一.IntelliJ IDEA 2017 下载地址 http://www.jetbrains.com/idea/#chooseYourEdition 要下载付费版的,免费版的很多功能不能用 二.破解 ...
- hibernate从零开始到各种映射
ORM(对象/关系数据库映射) 对象关系映射(Object Relational Mapping,简称ORM)是一种为了解决面向对象与关系数据库存在的互不匹配的现象的技术.它完成了面向对象的编程语言到 ...
- Objective C 中的BOOL, bool, Boolean理解
一. 1.类型不同 BOOL为int型 bool为布尔型 2.长度不同 bool只有一个字节 BOOL长度视实际环境来定,一般可认为是4个字节 3.取值不同 bool取值false和true,是0和1 ...
- fireworks图片边缘化 fireworks羽化图片边缘的教程
fireworks羽化图片边缘的教程如下: 1. 打开一个图片. 2.点击“工具”面板“位图”部分的“选取框”工具.也可以选择“椭圆选取框”工具. 3.选择部分图象. 4.在属性检查器中,“边缘”项中 ...
- 转:SQL Server附加数据库提示“版本为661,无法打开,支持655版本……”
在我们使用别人导出的数据库的时候,有时候我们会通过附加数据库的方法,把别人导出的数据库附加到我们的电脑中,这时,或许你会遇到这种问题,附加时,提示版本为XXX,无法打开,支持AAA版本. 这是怎么回事 ...
- 创建 XMLHttpRequest 对象时IE的兼容问题解决办法
为了应对所有的现代浏览器,包括 IE5 和 IE6,请检查浏览器是否支持 XMLHttpRequest 对象.如果支持,则创建 XMLHttpRequest 对象.如果不支持,则创建 ActiveXO ...