POJ 3982 序列(高精度加法)
来源:互联网 发布:了不起的nodd.js 编辑:程序博客网 时间:2024/06/05 15:36
数列A满足An = An-1 + An-2 + An-3, n >= 3
编写程序,给定A0, A1 和 A2, 计算A99
编写程序,给定A0, A1 和 A2, 计算A99
输入包含多行数据
每行数据包含3个整数A0, A1, A2 (0 <= A0, A1, A2 <= 32767)
数据以EOF结束
每行数据包含3个整数A0, A1, A2 (0 <= A0, A1, A2 <= 32767)
数据以EOF结束
对于输入的每一行输出A99的值
1 1 1
69087442470169316923566147
思路:
直接高精度模拟就好了,直接套模板
代码:
#include<iostream>#include<cstring>#include<stdio.h>#include<math.h>#include<string>#include<stdio.h>#include<queue>#include<stack>#include<map>#include<vector>#include<deque>#include<algorithm>using namespace std;#define lson k*2#define rson k*2+1#define M (t[k].l+t[k].r)/2#define INF 100861111#define ll long long#define eps 1e-15class bigInt{public: int num[302], len; bigInt() { num[0] = 0, len = 0; } void operator=(const int &a) { int tmp = a; len = 0; while (tmp) num[len++] = tmp % 10, tmp /= 10; if (!len) num[0] = 0, len = 1; } bigInt(const int &a) { int tmp = a; len = 0; while (tmp) num[len++] = tmp % 10, tmp /= 10; if (!len) num[0] = 0, len = 1; } bigInt operator+(const bigInt &a) { bigInt res; int i, j, c = 0, adda, addb; for (i = 0, j = 0; i < len || j < a.len || c; ) { adda = 0, addb = 0; if (i < len) adda = num[i++]; if (j < a.len) addb = a.num[j++]; res.num[res.len++] = (adda + addb + c) % 10; c = (adda + addb + c) / 10; } return res; } void display() { int i; for (i = len - 1; i > 1; i--) if (num[i]) break; for (; i >= 0; i--) printf("%d", num[i]); printf("\n"); }};int main(){ int a,b,c,i; while(scanf("%d%d%d",&a,&b,&c)!=EOF) { bigInt x,y,z,t; y=a; z=b; t=c; for(i=1;i<=97;i++) { x=y; y=z; z=t; t=x+y; t=t+z; } t.display(); } return 0;}
阅读全文
0 0
- POJ 3982 序列(高精度加法)
- POJ 3982 序列(高精度)
- poj 2389 Bull Math(高精度加法)
- poj 1503 高精度加法
- poj 1503 高精度加法
- poj 1503 高精度加法,累加
- poj 3982- 序列-大整数加法
- poj 2756 Autumn is a Genius(高精度加法)
- 大数(高精度)加法
- 二进制(高精度加法)
- 高精度加法(c++)
- 高精度(加法)
- POJ 1503 Integer Inquiry 高精度加法
- POJ 1503(高精度整数加法) 解题报告
- POJ 1503 Integer Inquiry 高精度加法
- poj 2413 高精度加法,裴波拉契,判断范围
- poj 1503 大整数高精度 加法
- 高精度整数加法(大整数加法)
- 点到三维网格最近点距离
- Android Gradle文件各种bug汇总
- 更改Anaconda下载源,提高下载速度
- java 线程池讲解
- Keras:1 基础知识与安装
- POJ 3982 序列(高精度加法)
- 2017 Multi-University Training Contest
- 8.24--练习赛D题--Treats for the cows(区间DP)
- Android消息机制梳理
- 【C#学习】可空类型
- 程序员必备基础知识:通信协议——Http、TCP、UDP
- uva 10820 Send a Table 欧拉函数
- 【深入PHP 面向对象】读书笔记(五)
- 导入工程出错