UVa10288
来源:互联网 发布:模糊查询的sql语句 编辑:程序博客网 时间:2024/06/10 08:51
Coupons in cereal boxes are numbered 1 to n, and a set of one of each is required for a prize (a cerealbox, of course). With one coupon per box, how many boxes on average are required to make a completeset of n coupons?InputInput consists of a sequence of lines each containing a single positive integer n, 1 ≤ n ≤ 33, giving thesize of the set of coupons. Input is terminated by end of file.OutputFor each input line, output the average number of boxes required to collect the complete set of ncoupons. If the answer is an integer number, output the number. If the answer is not integer, thenoutput the integer part of the answer followed by a space and then by the proper fraction in the formatshown below. The fractional part should be irreducible. There should be no trailing spaces in any lineof output.Sample Input2517Sample Output3 511 -- 12 34046358 ------ 720720
假设当前已经拿到了K种奖券
从箱子中取出一种新奖券的概率是(n-K)/n
平均要取n/(n-K)次
所以ans=
#include<iostream>#include<cstdlib>#include<cstdio>#include<string>#include<vector>#include<deque>#include<queue>#include<algorithm>#include<set>#include<map>#include<stack>#include<ctime>#include <string.h>#include<math.h>using namespace std;#define ll long long#define pii pair<int,int>const int inf=1e9+7;struct Num{ ll fz,fm; ll gcd(ll a,ll b)const{ return b?gcd(b,a%b):a; } Num(){ fz=0,fm=1; } Num(ll fz,ll fm){ this->fz=fz; this->fm=fm; } Num operator+(const Num&x)const{ Num ans; ans.fm=fm*x.fm; ans.fz=fz*x.fm+fm*x.fz; ll d=gcd(ans.fz,ans.fm); ans.fz/=d; ans.fm/=d; return ans; }};int len(ll x){ int len=0; while(x){ x/=10; ++len; } return len;}void print(const Num&x){ if(x.fm==1){ printf("%lld\n",x.fz); } else{ ll ansInt=x.fz/x.fm; int ansIntLen=len(ansInt); Num ansFloat=x; ansFloat.fz-=x.fm*ansInt; int fmLen=len(x.fm); for(int i=0;i<=ansIntLen;++i){ putchar(' '); } printf("%lld\n",ansFloat.fz); printf("%lld ",ansInt); for(int i=0;i<fmLen;++i){ putchar('-'); } putchar('\n'); for(int i=0;i<=ansIntLen;++i){ putchar(' '); } printf("\%lld\n",ansFloat.fm); }}int main(){ //freopen("/home/lu/Documents/r.txt","r",stdin); int n; while(~scanf("%d",&n)){ Num ans; for(int i=0;i<n;++i){ ans=ans+Num(n,n-i); } print(ans); } return 0;}
0 0
- UVa10288
- UVa10288
- UVa10288
- UVA10288 Coupons
- UVA10288 Coupons
- uva10288 Coupons
- [UVA10288] Coupons && 数学期望
- uva10288(数学期望)
- 【ACM刷题录】UVa10288 Coupons
- Uva10288(概率期望+暴力模拟)
- 【Uva10288】——Coupons概率
- UVA10288 - Coupons (概率+递推)
- UVA10288 Coupons(卡输出神题)
- UVa10288优惠券(紫书333)(期望)
- HTML Meta中添加X-UA-Compatible和IE=Edge,chrome=1有什么作用?
- Codeforces Round #401 (Div. 2) 题解
- LeetCode 6. ZigZag Conversion
- 1. Two Sum easy
- MAC下搭建appium UI自动化环境详细步骤
- UVa10288
- 一步一步在Windows中使用MyCat负载均衡 上篇
- java多线程常用关键字与方法介绍(二)
- web.xml中配置乱码过滤器
- [MySQL]--关于索引操作的SQL
- MySchool 04 高级查询 上机题
- NOIP 乘积最大(dp)
- Orcale 游标
- git学习笔记