hdu 1099(数学)
Lottery
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 3333 Accepted Submission(s): 1489
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?
consists of a sequence of lines each containing a single positive
integer n, 1<=n<=22, giving the size of the set of coupons.
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.
5
17
5
11 --
12
340463
58 ------
720720
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
typedef long long LL;
LL gcd(LL a,LL b){
return b==?a:gcd(b,a%b);
}
LL lcm(LL a,LL b){
return a/gcd(a,b)*b;
}
int getLen(LL num){
int ans = ;
while(num){
ans++;
num/=;
}
return ans;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
LL a=,b=; ///a为分子,b为分母
for(int i=;i<=n;i++){
a = a*i+b;
b = b*i;
LL d = gcd(a,b);
a/=d;
b/=d;
}
a=a*n;
LL d = gcd(a,b);
a/=d,b/=d;
LL res = a/b;
if(a%b==){
printf("%lld\n",a/b);
}else {
LL len = getLen(res);
LL len1 = getLen(b);
LL yushu = a%b;
for(int i=;i<=len;i++){
printf(" ");
}
printf("%lld\n%lld ",yushu,res);
for(int i=;i<len1;i++) printf("-");
printf("\n");
for(int i=;i<=len;i++){
printf(" ");
}
printf("%lld\n",b);
}
}
return ;
}
hdu 1099(数学)的更多相关文章
- hdu 1099 Lottery
这是我第一次写博客,作为一个ACMer,经常进别人的博客,所以自己也想写写博客. HDU 1099 Lottery Time Limit: 2000/1000 MS (Java/Others) ...
- HDU 5984 数学期望
对长为L的棒子随机取一点分割两部分,抛弃左边一部分,重复过程,直到长度小于d,问操作次数的期望. 区域赛的题,比较基础的概率论,我记得教材上有道很像的题,对1/len积分,$ln(L)-ln(d)+1 ...
- HDU 1099 Lottery (求数学期望)
传送门: http://acm.hdu.edu.cn/showproblem.php?pid=1099 Lottery Time Limit: 2000/1000 MS (Java/Others) ...
- HDU - 1099 - Lottery - 概率dp
http://acm.hdu.edu.cn/showproblem.php?pid=1099 最最简单的概率dp,完全是等概率转移. 设dp[i]为已有i张票,还需要抽几次才能集齐的期望. 那么dp[ ...
- HDU 5976 数学,逆元
1.HDU 5976 Detachment 2.题意:给一个正整数x,把x拆分成多个正整数的和,这些数不能有重复,要使这些数的积尽可能的大,输出积. 3.总结:首先我们要把数拆得尽可能小,这样积才会更 ...
- *HDU 2451 数学
Simple Addition Expression Time Limit: 5000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Ja ...
- [ An Ac a Day ^_^ ] hdu 4565 数学推导+矩阵快速幂
从今天开始就有各站网络赛了 今天是ccpc全国赛的网络赛 希望一切顺利 可以去一次吉大 希望还能去一次大连 题意: 很明确是让你求Sn=[a+sqrt(b)^n]%m 思路: 一开始以为是水题 暴力了 ...
- hdu 4506(数学,循环节+快速幂)
小明系列故事——师兄帮帮忙 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Tot ...
- hdu 4432 数学杂题
http://acm.hdu.edu.cn/showproblem.php?pid=4432 6分钟写的代码,一上午去调试,, 哎,一则题目没看懂就去写了,二则,哎,,恶心了.在坚持几天然后ACM退役 ...
随机推荐
- (73)zabbix用户认证方式 内建、HTTP Basic、LDAP
公司大大小小众多系统,不同系统不同的账号密码,管理上相当复杂,后来慢慢出现了SSO等账号统一验证,其他zabbix也提供了类似的方法,或许有些公司便可以使用公司提供的账号来登录zabbix了. zab ...
- 将远程分支拷贝到本地,并更新代码push到原分支
第一步:git clone +主分支 第二步:git fetch origin 分支名 第三步:git checkout -b 分支名 origin/分支名 第四步:git pull origin 分 ...
- 笔记--Day1--python基础1
一.目录 1.Python介绍 python的创始人为吉多·范罗苏姆(Guido van Rossum),目前已经是使用频度特别高的开发语言. 主要应用领域: 云计算:云计算最火的语言,典型应用有Op ...
- 使用三层交换配置DHCP为不同VLAN分配IP地址
三层交换的原理以及DHCP的原理,作者在这里就不详细的解释了,在这里通过一个案例来了解使用三层交换做DHCP服务器,并为不同网段分配IP地址.在生产环境中,使用路由器或交换机做DHCP服务器要常见一些 ...
- DNS预解析 dns-prefetch
1.DNS 是什么? Domain Name System,域名系统,作为域名和IP地址相互映射的一个分布式数据库. DNS大家都懂,那么浏览器访问域名的时候,是需要去解析一次DNS,也就是把域名 g ...
- drf 视图功能
视图 drf提供的视图功能 自己的第一次封装 #一个功能写成一个类,方便组合,只要继承它就可以有这个功能 #将功能都写在一个类中,可控性就会变差 from book.myserializers imp ...
- Python入门基本语法
Python入门 以下主要讲述Python的一些基础语法,包含行的缩进在python中的重要意义,python中常见的保留字和引号的使用,如何实现单行注释和多行注释. print("he ...
- LeetCode(283)Move Zeroes
题目 Given an array nums, write a function to move all 0's to the end of it while maintaining the rela ...
- hdu 6312
Problem Description Alice and Bob are playing a game.The game is played on a set of positive integer ...
- 启动Chrome浏览器弹出“You are using an unsupported command-line flag –ignore-certificate-errors. Stability and security will suffer”
采用如下代码: public static void launchChrome() { System.setProperty("webdriver.chrome.driver", ...