这是我第一次写博客,作为一个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. Android --- 图片的特效处理
  2. java程序员的NodeJS初识篇
  3. 启明云端分享|sigmastar ssd201\ssd202d 双网口开发板在ISP烧录UBOOT时常遇到的问题解答
  4. rqt teb参数动态调试工具_16.ROS常用工具:Rviz/rqt
  5. 前端学习(1780):前端调试之快速转存站点的方法
  6. H264视频压缩编码标准简介(一)
  7. delphi2007很卡_提升Delphi编程效率必须使用的快捷键(Delphi2007版本)
  8. php fping,【Linux 命令】fping ping 包间隔时间详解
  9. [经典]技术面试宝典: 很全面的算法和数据结构知识(含代码)
  10. SSH——Hibernate简单配置
  11. Visual Studio 2013下载及其安装
  12. 第5章、解析Hello,world!知其然,更要知其所以然(从零开始学Android)
  13. POJ 1862: Stripies
  14. UiPath发送包含图片或表格的邮件
  15. 辛东方重组百花园传媒 人员大调整
  16. 第二章 Binary Search
  17. 数字滚动插件——CountUp.js
  18. iPhone和iPad等苹果设备自主更新Beta系统
  19. emc整改措施及案例_EMC整改经典对策
  20. WSL嵌入式开发系列教程 4 —— 安装VS code

热门文章

  1. Java代码实现“年-月-日 上午/下午时:分:秒”
  2. MySQL 阿里巴巴JAVA开发手册-MySQL相关
  3. php正则字母,PHP匹配连续的数字或字母的正则表达式
  4. 爬虫实例九 豆瓣电影详情信息
  5. python怎么弄成黑色背景图片_怎么能把图片的黑色背景改成透明背景
  6. php xcache 例子,PHP       xcache
  7. 18. Django进阶:中间件
  8. ElementUI:tree鼠标浮动在某个节点背景色以及点击背景色修改
  9. Java编程:将五子棋棋盘内容用稀疏矩阵存储至磁盘,并从中重新读取内容——稀疏数组和算法
  10. HTML:常用特殊字符编码表(自用)