这是我第一次写博客,作为一个ACMer,经常进别人的博客,所以自己也想写写博客。

HDU 1099

Lottery

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 2648    Accepted Submission(s): 1191

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
2 5 17
Sample Output
3 5 11 -- 12 340463 58 ------ 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>
using namespace std;int n,s,a1,b1,a2,b2,s1,s2;
int gcd(int x,int y)
{int t;while (x%y!=0){t=x%y;x=y;y=t;}return y;
}
int f(int x,int y)
{int t1=a1,t2=b1;a1=t1*y+b1*x;b1=t2*y;int t=a1/b1;s+=t;a1-=t*b1;t=gcd(a1,b1);a1=a1/t;b1=b1/t;
}
int main()
{while (cin>>n){s=0;a1=0;b1=1;for (int i=1;i<=n;i++){f(n,i);}if (a1==0)cout <<s<<endl;//" "<<a1<<" "<<b1<<endl;else{int t1=0,t2=0,temp1=s,temp2=b1;while (temp1!=0){t1++;temp1/=10;}t1++;while (temp2!=0){t2++;temp2/=10;}for (int i=1;i<=t1;i++)cout <<" ";cout <<a1<<endl;cout <<s<<" ";for (int i=t2;i>=1;i--)cout <<"-";cout <<endl;for (int i=1;i<=t1;i++)cout <<" ";cout <<b1<<endl;}   }return 0;
}

转载于:https://www.cnblogs.com/arno-my-boke/p/4238137.html

hdu 1099 Lottery相关推荐

  1. hdu 1099 数学

    恶心的输出...... AC代码如下: #include <iostream> #include <cstdio> using namespace std;__int64 gc ...

  2. 杭电OJ分类题目(3)

    原题出处:HDOJ Problem Index by Type,http://acm.hdu.edu.cn/typeclass.php 杭电OJ分类题目(3) HDU Computational Ge ...

  3. ACM模块解析之 数论

    数  论 一.简介 数论是ACM中的重点内容.历年竞赛题目,一般都有1~2道题目与数论有密切关系.数论涉及的概念和算法很多,用途也非常广泛.掌握与数论有关的方法,是参赛者需要具备的必要技能.数论的学习 ...

  4. vbox共享文件夹 linux,Vbox下创建Linux和Windows的共享文件夹

    我的Vbox版本是4.3.6...在这里以win8和Ubuntu12.04之间共享文件举例 首先运行虚拟机,然后安装增强功能..这个增强功能很碉堡...能开启无缝模式和系统间的剪贴板共享等牛X功能 然 ...

  5. [转] HDU 题目分类

    转载来自:http://www.cppblog.com/acronix/archive/2010/09/24/127536.aspx 分类一: 基础题:1000.1001.1004.1005.1008 ...

  6. HDU题目分类啊!!!

    分类一(详细): 分类二: 基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.10 ...

  7. hdu 杭电题目分类

    View Code 1 1001 这个就不用说了吧 2 1002 简单的大数 3 1003 DP经典问题,最大连续子段和 4 1004 简单题 5 1005 找规律(循环点) 6 1006 感觉有点B ...

  8. HDU题目分类大全【大集合】

    基础题: 1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.  1032.1037.1040.1048.1056.105 ...

  9. HDU 5643 King's Game 打表

    King's Game 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5643 Description In order to remember hi ...

  10. HDU 3105 Fred's Lotto Tickets(数学题)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3105 Problem Description Fred likes to play the lotto ...

最新文章

  1. 子元素margin-top影响父标签原因
  2. 数字图像处理:第十七章 纹理分析
  3. dockerfile安装yum_Docker镜像-基于DockerFile制作yum版nginx镜像
  4. java设计模式观察者模式吗_Java设计模式之观察者模式原理与用法详解
  5. 和get redis_Springboot2连接redis哨兵模式
  6. pacs文件浏览工具_啥?网络攻击浏览器让你惊惶失措?这里教你防患未然
  7. php arrayfillkeys,PHP中的array_fill_keys()函数
  8. EdrawMax Crack,多合一的图表应用程序
  9. 图片识别不了小程序怎么办_图片转文字【小程序】
  10. 【转】Android开发人员不得不收集的代码(不断更新)
  11. 利用计算机制作多媒体作品目标,多媒体创作工具功能有什么特点
  12. 半监督语义分割_paper reading part2
  13. 数字三角形 计算最大路径 动态规划
  14. Nignx 网关 和 GateWay网关
  15. ls: 显示目下的内容及相关属性信息
  16. 小爬虫sitemap网站seo优化(黄梦岚)
  17. git clone使用指定用户名和密码
  18. 利用留数定理计算实积分进阶例子
  19. SM4国密算法原理及python代码实现
  20. display的各种属性

热门文章

  1. 最简单的List集合排序方法
  2. Thinking in Java 17.8 理解Map
  3. 百度地图,你必须知道的自定义Marker图标方法
  4. 阿里代码规范pdf_看完阿里的代码规范,立马学会代码分层,再也不会被同事怼...
  5. k8s部署应用nginx
  6. qq飞车手游微信新服务器失败,关于QQ飞车手游部分玩家更新失败的问题说明
  7. 计算机集群用什么网络,什么是计算机系统集群?
  8. python基础装饰器_Python基础之装饰器
  9. python requests text content_对python requests的content和text方法的区别详解
  10. jack插头_防水连接器航空插头特点