简单大数

(要压位,不然会超内存)

#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
using namespace std;
const int base = 1000000;
struct BigInt
{
vector<int> Num;
BigInt() { Num.clear(); }
void Set(int n) { Num.clear(); Num.push_back(n); }
BigInt operator + (const BigInt &a) const
{
BigInt c;
int len1 = Num.size(), len2 = a.Num.size();
int i;
for(i = 0; i < len1 && i < len2; ++i)
c.Num.push_back(Num[i] + a.Num[i]);
for(; i < len1; ++i) c.Num.push_back(Num[i]);
for(; i < len2; ++i) c.Num.push_back(a.Num[i]);
for(int i = 0; i < c.Num.size(); ++i)
{
if(c.Num[i] >= base)
{
if(i == c.Num.size() - 1) c.Num.push_back(c.Num[i] / base);
else c.Num[i+1] += c.Num[i] / base;
c.Num[i] %= base;
}
}
return c;
} void Print()
{
int len = Num.size();
printf("%d",Num[len-1]);
for(int i = len - 2; i >= 0; --i)
{
int k = base / 10;
while(Num[i] < k)
{
printf("0");
k /= 10;
}
printf("%d",Num[i]);
}
printf("\n");
}
}N[500000]; void Init()
{
N[1].Set(1);N[2].Set(1);
N[3].Set(1);N[4].Set(1);
for(int i = 5; ; ++i)
{
N[i] = N[i-1] + N[i-2] + N[i-3] + N[i-4];
if(N[i].Num.size() * 5 > 2005) break;
}
} int main()
{
Init();
int n;
while(cin >> n)
{
N[n].Print();
}
return 0;
}

HDU 1250的更多相关文章

  1. hdu 1250 Hat&#39;s Fibonacci

    pid=1250">点击此处就可以传送hdu 1250 Problem Description A Fibonacci sequence is calculated by adding ...

  2. hdu 1250 Hat's Fibonacci

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Description A Fibonacci sequence ...

  3. HDU 1250 Hat's Fibonacci(大数相加)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1250 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Ot ...

  4. hdu 1250 Hat's Fibonacci(java,简单,大数)

    题目 java做大数的题,真的是神器,来一道,秒一道~~~ import java.io.*; import java.util.*; import java.math.*; public class ...

  5. hdu 1250 Hat's Fibonacci(高精度数)

    //  继续大数,哎.. Problem Description A Fibonacci sequence is calculated by adding the previous two membe ...

  6. HDOJ/HDU 1250 Hat's Fibonacci(大数~斐波拉契)

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  7. Hat's Fibonacci hdu 1250

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  8. HDU 1250 Hat's Fibonacci(高精度)

    Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequen ...

  9. hdu 1250 树形DP

    Anniversary party Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u S ...

随机推荐

  1. vue-router拦截

    说明:以下均在main.js中添加. 主要思路 1.在路由分发时,检查本地缓存是否有账号信息,如果没有,跳转登陆页面,传入当前路由 2.在发送请求时,添加账号token 3.在接收请求时,检查响应的数 ...

  2. MySQL C API概述

    以下列表总结了C API中可用的功能.有关更多详细信息,请参见 第27.8.7节“C API函数描述”中的说明. my_init():在线程安全程序中初始化全局变量和线程处理程序 mysql_affe ...

  3. 【noip 2012】提高组Day2T3.疫情控制

    Description H国有n个城市,这n个城市用n-1条双向道路相互连通构成一棵树,1号城市是首都,也是树中的根节点. H国的首都爆发了一种危害性极高的传染病.当局为了控制疫情,不让疫情扩散到边境 ...

  4. 深度学习 ——style reconstruction

    多层神经网络的实质就是为了找出更复杂,更内在的features...图像的style, how to describe, impossible! 但是人眼却可以分辨. (参考论文 A Neural a ...

  5. python 爬虫得到网页的图片

    import urllib.request,os import re # 获取html 中的内容 def getHtml(url): page=urllib.request.urlopen(url) ...

  6. matplotlib-形状

    需要   import matplotlib.patches as mp import numpy as np import matplotlib.pyplot as plt import matpl ...

  7. PHP cURL实现模拟登录与采集使用方法详解教程

    来源:http://www.zjmainstay.cn/php-curl 本文将通过案例,整合浏览器工具与PHP程序,教你如何让数据 唾手可得 . 对于做过数据采集的人来说,cURL一定不会陌生.虽然 ...

  8. Codeforces891C(892E)

    传送门:here 简述题意:                                                                                       ...

  9. Spring中@Transactional(rollbackFor = Exception.class)的作用

    Spring中的@Transactional(rollbackFor = Exception.class)事务处理,当你的方法中抛出异常时,它会将 事务回滚,数据库中的数据将不会改变,也就是回到进入此 ...

  10. AngularJS--及其他js框架对比

    ----和 **类似?? Angular 2.谷歌的 React   Facebook的 Vue.js. Ember.js. https://github.com/angular/angular.js ...