简单大数

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

#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. python 可视化库

    在做titanic分析的过程中,看了一些大神的想法,发现在分析数据的过程中,许多大神会使用到seaborn,plotly这些库,而我等小白仅仅知道matplotlib这个唯一的数据可视化库而已.上网查 ...

  2. 细说logback之简介

    官网:https://logback.qos.ch/https://logback.qos.ch/manual/index.html logback手册1.下载logback是slf4j的原生实现,所 ...

  3. ETL脚本的版本管理方法和 SourceTree 使用

    =============================使用git管理Kettle 作业的一个注意=============================之前 ETL 作业是用 svn 管理的, ...

  4. html取消回车刷新提交

    <form class="weui-search-bar__form" onsubmit="return false;"> <form cla ...

  5. C++ WString与String互相转换

    std::wstring StringToWString(const std::string& str) { , str.c_str(), -, NULL, ); wchar_t *wide ...

  6. 用EditPlus和jdk写Java代码

    一.安装EditPlus EditPlus: https://www.editplus.com/latest4.html EditPlus注册码在线生成: https://www.jb51.net/t ...

  7. 使用flask_socketio实现客户端间即时通信

    前期没有来得及好好总结,现在复习总结一下: Socket.IO 背后主要的思想是你可以发送和接收想要的任何事件,携带你想要的任何数据.任何可以编码为 JSON 的对象都可以做到,并且也支持二进制数据. ...

  8. JDK1.8源码分析之Comparable && Comparator

    import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util. ...

  9. SQLQueryStress

    工具介绍及使用链接:http://www.cnblogs.com/lyhabc/p/3187922.html 工具下载链接:http://files.cnblogs.com/files/coce/sq ...

  10. python3.7中asyncio的具体实现

    讲讲我在使用python异步IO语法时踩过的坑 简单介绍异步IO的原理 以及利用最新语法糖实现异步IO的步骤, 然后给出实现异步的不同例子 网上找了很多python的asyncio示例.很多都是用 # ...