UVA 10288 Coupons
来源:互联网 发布:在家网络医疗咨询 编辑:程序博客网 时间:2024/05/21 10:27
CouponsCrawling in process...Crawling failedTime Limit:3000MS Memory Limit:0KB 64bit IO Format:%lld & %llu
Description
Problem F
Coupons
Input: standard input
Output: standard output
Time Limit:2 seconds
Memory Limit:32 MB
Coupons in cereal boxes are numbered1 to n, and a set of one of each is required for a prize (a cereal box, of course). With one coupon per box, how many boxes 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 integern, 1<=n<=33, giving the size of the set of coupons. Input is terminated by end of file.
Output
For each input line, output the average number of boxes required to collect the complete set ofn 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 output.
Sample Input
2
5
17
Sample Output
3
5
11 --
12
340463
58 ------
720720
(Math Lovers Contest, Source: University of Alberta Local Contest)
题意:题目意思一开始没看懂啦,后来得知是求http://zh.wikipedia.org/wiki/%E8%B4%88%E5%88%B8%E6%94%B6%E9%9B%86%E5%95%8F%E9%A1%8C(戳了你就知道啦)。
思路:看上面的链接啦。
#include <cassert>#include <cstdio>#include <iostream>#include <algorithm>#include <cmath>#include <cstring>#include <stdlib.h>using namespace std;typedef long long ll;ll gcd(ll a,ll b){ return b?gcd(b,a%b):a;}struct frac{ ll up,low; frac(ll up=0,ll low=1){ if(low<0) up=-up,low=-low; assert(low); ll g=gcd(abs(up),low); this->up=up/g,this->low=low/g; } frac operator + (const frac &b) const{return frac(up * b.low + low * b.up, low * b.low);}frac operator - (const frac &b) const{return frac(up * b.low - low * b.up, low * b.low);}frac operator * (const frac &b) const{return frac(up * b.up, low * b.low);}frac operator / (const frac &b) const{return frac(up * b.low, low * b.up);}bool operator < (const frac &b) const{return up * b.low < low * b.up;}bool operator == (const frac &b) const{return up * b.low == low * b.up;}bool operator > (const frac& b) const{return b < *this;}bool operator <= (const frac& b) const{return !(b < *this);}bool operator >= (const frac &b) const{return !(*this < b);}bool operator != (const frac &b) const{return up * b.low != low * b.up;}frac operator += (const frac &b){return *this = *this + b;}frac operator -= (const frac &b){return*this = *this - b;}frac operator *= (const frac &b){return *this = *this * b;}frac operator /= (const frac &b){return *this = *this / b;}};int main(){ int n; while(~scanf("%d",&n)){ frac ans[100]; ans[1]=frac(1,1); for(int i=2;i<=n;i++){ ans[i]=ans[i-1]+frac(1,i); } ans[n]*=frac(n,1); ll a,b,c; a=ans[n].up/ans[n].low; b=ans[n].up%ans[n].low; c=ans[n].low; if(a&&b){ ll t=1; while(a>=t){ printf(" "); t*=10; } printf(" "); } if(b) printf("%lld\n",b); if(a) printf("%lld",a); if(b){ printf(" "); ll t=1; while(c>=t){ printf("-"); t*=10; } } printf("\n"); if(a&&b){ ll t=1; while(a>=t){ printf(" "); t*=10; } printf(" "); } if(b)printf("%lld\n",c); } return 0;}
- Uva 10288 - Coupons
- UVA 10288 - Coupons
- uva 10288 coupons
- UVA 10288 Coupons
- uva 10288 - Coupons(概率)
- UVA 10288 - Coupons
- UVa 10288 Coupons
- UVA 10288(p333)----Coupons
- uva 10288 Coupons
- uva 10288 Coupons
- Uva 10288 Coupons
- UVA 10288 Coupons
- Coupons - UVa 10288 概率dp
- 【UVA】10288-Coupons(概率)
- uva 10288 Coupons 数学期望
- UVA 10288 Coupons 数学期望
- Coupons UVA
- UVA 10288 - Coupons(概率递推)
- 学习php需要了解的点4 - PHP中file_get_contents函数抓取https地址出错的解决方法
- 使用java程序比较mysql表结构
- Cocos2d-x 3.1.1 学习日志11--一Windows下Android环境搭建(一定对你有用的!!)
- Android Handler通信
- 神奇的母函数(二) hdoj 1398 Square Coins 【母函数】
- UVA 10288 Coupons
- ExtJs桌面组件
- Mybatis
- hibernate缓存
- C++文件操作详解(ifstream、ofstream、fstream)
- JSTL标签
- Linuxcurl命令参数详解
- Composer创建和发送HTTP Request
- CodeVs 3315 时空跳跃者的魔法(最终版本)