POJ-1405 Heritage-高精度加减乘
来源:互联网 发布:淘宝家装设计 编辑:程序博客网 时间:2024/04/27 19:57
Heritage
Time Limit: 1000MS Memory Limit: 65536KTotal Submissions: 7370 Accepted: 2743
Description
Your rich uncle died recently, and the heritage needs to be divided among your relatives and the church (your uncle insisted in his will that the church must get something). There are N relatives (N <= 18) that were mentioned in the will. They are sorted in descending order according to their importance (the first one is the most important). Since you are the computer scientist in the family, your relatives asked you to help them. They need help, because there are some blanks in the will left to be filled. Here is how the will looks:
Relative #1 will get 1 / ... of the whole heritage,
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.
The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.
Relative #1 will get 1 / ... of the whole heritage,
Relative #2 will get 1 / ... of the whole heritage,
---------------------- ...
Relative #n will get 1 / ... of the whole heritage.
The logical desire of the relatives is to fill the blanks in such way that the uncle's will is preserved (i.e the fractions are non-ascending and the church gets something) and the amount of heritage left for the church is minimized.
Input
The only line of input contains the single integer N (1 <= N <= 18).
Output
Output the numbers that the blanks need to be filled (on separate lines), so that the heritage left for the church is minimized.
Sample Input
2
Sample Output
23
Source
ural 1108
根据题目意思就是说,后一个人的分母N是前一个人的分母M进行M*(M-1)+1的计算所得。
然后用高精度加减乘就可以算出来~
根据题目意思就是说,后一个人的分母N是前一个人的分母M进行M*(M-1)+1的计算所得。
然后用高精度加减乘就可以算出来~
#include<stdio.h>#include<stdlib.h>#define inf 1000000000#define maxn 100000int len1, len2, len3, len[18];long long a[maxn], b[maxn], ans[maxn], res[18][maxn];void setAns(){ for (int i = 0; i < len3; i++) { ans[i] = 0; }}void copy(){ for (int i = 0; i < len3; i++) { a[i] = ans[i]; } len1 = len3;}void multiply(){ int i, j; setAns(); for (i = 0; i < len2; i++) { for (j = 0; j < len1; j++) { ans[i+j] += a[j] * b[i]; ans[i+j+1] += ans[i+j] / inf; if (ans[i+j+1] && len3 <= i + j + 1) { len3 = i + j + 2; } else if (len3 <= i + j) { len3 = i + j + 1; } ans[i+j] %= inf; } }}void plus(){ int r; for (len2 = 0, r = 1; len2 < len1; len2++) { r += a[len2]; if (r >= inf) { b[len2] = r - inf; r = 1; } else { b[len2] = r; r = 0; } } if (r) { b[len2++] = r; }}int main(){ int i, j, n; scanf("%d", &n); a[0] = 2; len1 = 1; printf("2\n"); for (i = 2; i <= n; i++) { plus(); printf("%lld", b[len2-1]); for (j = len2 - 2; j >= 0; j--) { printf("%.9lld", b[j]); }printf("\n"); if (i < n) { multiply(); copy(); } } return 0;}
0 0
- POJ-1405 Heritage-高精度加减乘
- (高精度运算4.7.32)POJ 1405 Heritage(大数累乘)
- POJ 1405 Heritage(高精度)
- poj 1405 Heritage java 高精度
- POJ 1405 Heritage(模拟+高精度乘法)
- 高精度加减乘模版
- 高精度加减乘运算
- 【模板】高精度--加减乘
- 高精度(加减乘)改
- 转载高精度加减乘除法
- 【模板】高精度(加减乘)
- 【模板】高精度 加减乘 重载法
- 【高精度计算】加减乘模板(水)
- POJ 1405 Heritage
- POJ 1405 Heritage
- POJ 1405 Heritage 笔记
- 【高精度模板】【高精加减乘没有除】
- Heritage(高精度)
- 使用Bitmap做数据分析统计
- shell中各种括号的作用()、(())、[]、[[]]、{}
- Android-布局优化(include , merge , ViewStub)
- 如何向GitHub提交更改的代码
- 程序员的年龄天花板
- POJ-1405 Heritage-高精度加减乘
- IOS 退出程序APP代码
- 分治:二分搜索法算法的java实现
- 使用CUBLAS的一些小例子
- 归途
- MyBatis简介与配置MyBatis+Spring+MySql
- Introduction to Java Programming编程题9.8<二进制转十进制>
- 《小明的手机不见了?》
- 已解决:goldengate可以正常insert同步数据,但update不同步数据,也没有错误提示。