UVA10288 Coupons(卡输出神题)
来源:互联网 发布:javaweb购物网站源码 编辑:程序博客网 时间:2024/06/10 21:30
给出n,求Σn/i (i = 1 to n,n<=33)
分数的基本运算,首先打好表。
#include<cstdio>using namespace std;typedef long long LL;struct T{LL zs,fz,fm;//整数,分子,分母T(){zs = 0,fz = 0,fm = 1;}T(LL a,LL b,LL c){zs = a;fz = b;fm = c;}}ans[50];LL gcd(LL a,LL b){if(b == 0) return a;else return gcd(b,a%b);}T add(T a,T b){a.zs += a.fz/a.fm;b.zs += b.fz/b.fm;a.fz %= a.fm;b.fz %= b.fm;T temp;LL dd = gcd(a.fz*b.fm + a.fm*b.fz,a.fm*b.fm);temp.zs = a.zs+b.zs;temp.fz = (a.fz*b.fm + a.fm*b.fz)/dd;temp.fm = a.fm*b.fm/dd;temp.zs += temp.fz/temp.fm;temp.fz %= temp.fm;return temp;}void init(){for(int n = 1; n <= 33; n++)for(int i = 1; i <= n; i++)ans[n] = add(ans[n],T(0,n,i));}int getlen(LL x){int len = 0;while(x){len++;x /= 10;}return len;}void print(T x){if(x.fz == 0) {printf("%lld\n",x.zs); return;}for(int i = 1; i <= getlen(x.zs)+1; i++)printf(" ");printf("%lld\n",x.fz);printf("%lld ",x.zs);for(int i = 1; i<= getlen(x.fm); i++)printf("-");printf("\n");for(int i = 1; i <= getlen(x.zs)+1; i++)printf(" ");printf("%lld\n",x.fm);}int main(){init();int n;while(scanf("%d",&n) != EOF){print(ans[n]);}}
0 0
- UVA10288 Coupons(卡输出神题)
- UVA10288 Coupons
- UVA10288 Coupons
- uva10288 Coupons
- [UVA10288] Coupons && 数学期望
- 【ACM刷题录】UVa10288 Coupons
- 【Uva10288】——Coupons概率
- UVA10288 - Coupons (概率+递推)
- UVa10288
- UVa10288
- UVa10288
- Coupons
- Coupons and Discounts(细节题)
- uva10288(数学期望)
- ACM Coupons
- poj2625 Coupons
- Coupons UVA
- Uva10288(概率期望+暴力模拟)
- NAND flash和NOR flash的区别详解
- Fragment
- 初识Python之刨根问底
- Android之——多媒体开发视频格式
- 算法竞赛入门经典:第七章 暴力求解法 7.5枚举排列
- UVA10288 Coupons(卡输出神题)
- MySQL 调优/优化的 100 个建议
- android 多线程下载断点续传
- codeforces 508E E. Arthur and Brackets(栈模拟+贪心+构造)
- poj-2503-Babelfish-字典树orMAP or 字符串哈希
- [搜索or枚举]AOJ 0525 Osenbei
- Python的函数参数
- 动态规划-0-1背包问题
- io流(一)