URAL - 1108 Heritage(大数)
来源:互联网 发布:mac开机问号文件夹 编辑:程序博客网 时间:2024/04/28 09:28
恶心的大数运算,,,
比赛的时候,如果没有模版,一般置后的题目了,,,,
题意:
要求a,b,c,.....使得1-1/a-1/b-1/c-1/d.......的结果最小。。。
代码如下:
#include <cstdio>#include <cstring>#define MOD 100000000long long ans[100000], last[100000], temp[100000];int ans_l, last_l;void add(){ for(int i = 0; i < last_l; ++i) ans[i] = last[i]; ans_l = last_l; ans[0]+=1; for(int i = 0; i < ans_l; ++i) { ans[i+1] += ans[i]/MOD; ans[i] %= MOD; } while(ans[ans_l]!=0) { ans[ans_l+1] += ans[ans_l]/MOD; ans[ans_l] %= MOD; ans_l += 1; }}void product(){ int temp_l = last_l+ans_l-1; memset(temp,0,sizeof(temp)); for(int i = 0; i < last_l; ++i) for(int j = 0; j < ans_l; ++j) temp[j+i]+=last[i]*ans[j]; for(int i = 0; i < temp_l; ++i) { temp[i+1] += temp[i]/MOD; temp[i]%=MOD; } while(temp[temp_l]!=0) { temp[temp_l+1] += temp[temp_l]/MOD; temp[temp_l] %= MOD; temp_l += 1; } for(int i = 0; i < temp_l; ++i) last[i] = temp[i]; last_l = temp_l;}void print(){ for(int i = ans_l-1; i >= 0; i--) i==ans_l-1?printf("%I64d", ans[i]):printf("%08I64d", ans[i]); printf("\n");}int main (){ int n; scanf("%d",&n); memset(ans,0,sizeof(ans)); memset(last,0,sizeof(last)); last[0] = 1; last_l = ans_l = 1; for(int i = 1; i <= n; ++i) { add(); print(); product(); } return 0;}
- URAL - 1108 Heritage(大数)
- URAL 1108. Heritage 高精度大数乘法
- Ural 1048 大数雏形
- (高精度运算4.7.32)POJ 1405 Heritage(大数累乘)
- Ural 1158. Censored! AC自动机+大数
- URAL 1513. Lemon Tale 好多大数
- URAL 1036. Lucky Tickets(dp+大数)
- ural 1108
- usaco heritage
- usaco--heritage
- poj1405-Heritage
- American Heritage
- American Heritage
- USACO 3.4 American Heritage (heritage)
- USACO3.4.1 American Heritage (heritage)
- USACO3.4.1 American Heritage(heritage)
- POJ-1625 & ZOJ-1540 & Ural-1158 AC自动机+DP+大数..
- URAL 1903 Unidentified Ships(大数组合数打表取模)
- 整理了一下Xcode快捷键,史上最全!
- hdu 2859
- 怎么快速去掉代码行前的数字
- 没有对“C:\WINDOWS\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files”的写访问权限
- PostgreSQL的中文全文检索
- URAL - 1108 Heritage(大数)
- 子窗口使用父窗口的控件
- hdu 1372 Knight Moves(最基本的BFS)
- Android selector item 属性大全
- Hibernate映射自定义数据类型
- SecureCRT的sz/rz工具包
- Java Web 高性能开发,第 1 部分: 前端的高性能
- Codeforces Round #194 (Div. 2) A. Candy Bags
- sed的替换操作