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 ...
随机推荐
- TCP字节流与UDP数据报(转)
关于TCP和UDP的分次发送和接收的问题,困惑了两天,看到这篇文章豁然开朗. 原文链接:http://network.51cto.com/art/201310/413326.htm “TCP是一种流模 ...
- ObjectHeader、ObjectType和ObjectHook的学习
0x01 前言 之前研究RootKit技术,发现了对象钩子这个概念,一直不知道是什么,然后在网上搜,最先找到的是sudami的一篇文章,于是跟着大牛的脚步研究,其中也参考<内核情景分析>, ...
- 《Python编程从入门到实践》_第二章_变量和简单数据类型
什么是变量 举例: >>> message = "Hello,Python!" >>> print (message) Hello,Python ...
- [转]NLog Layout Renderers ${}
https://github.com/nlog/NLog/wiki/Layout-Renderers Layout renderers are template macros that are use ...
- Observer(观察者)设计模式[转]
Observer设计模式中主要包括如下两类对象: Subject:监视对象,它往往包含着其他对象所感兴趣的内容.在本范例中,热水器就是一个监视对象,它包含的其他对象所感兴趣的内容,就是tempratu ...
- 1.net平台
.net/dotnet:一般指的是.Net Framework框架,是一种平台,一种技术. .net Framewoek框架是.net平台不可缺少的一部分,它提供了一个稳定的运行环境来保证.net ...
- Java使用UDP聊天程序
主要想测试Java UDP通信.Java UDP使用DatagramSocket和DatagramPacket完成UDP通信 主要思路: 1.本机通信,ip地址为:127.0.0.1 2.开一个线程监 ...
- struts2 :Unable to load configuration. ……struts-default.xml:46:178异常解决
这个问题是缺少jar包 除了ognl-2.6.11.jar,struts2-core-2.1.6.jar,xwork-2.1.2.jar,commons-logging-1.0.4.jar外, 还需要 ...
- CRM——销售与客户
一.销售与客户——表结构 1.客户类型 (1)公共客户(公共资源) 必备条件:没有报名: 在必备条件满足的情况下,满足以下任意条件都是公共客户: 3天没有跟进:15天没有成单. (2)我的客户 原销售 ...
- 从list中随机选出几个数,并按照原来的顺序排列
需求: 从list中随机选出几个数,并按照原来的顺序排列(比如从list中随机选出6个数) 方案一: //若对象size大于6,则随机去除6个对象,并按照原来的顺序排列 while(list.size ...