hdu 1250 Hat's Fibonacci

题目连接

http://acm.hdu.edu.cn/showproblem.php?pid=1250

Hat's Fibonacci

Description

A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1.
$F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n > 4) = F(n - 1) + F(n-2) + F(n-3) + F(n-4)$
Your task is to take a number as input, and print that Fibonacci number.

Input

Each line will contain an integers. Process to end of file.

Output

For each case, output the result in a line.

SampleInput

100

SampleOutput

4203968145672990846840663646

大数加法模板题。。

  1 #include<algorithm>
  2 #include<iostream>
  3 #include<cstdlib>
  4 #include<cstring>
  5 #include<cassert>
  6 #include<cstdio>
  7 #include<vector>
  8 #include<string>
  9 #include<map>
 10 #include<set>
 11 using std::cin;
 12 using std::max;
 13 using std::cout;
 14 using std::endl;
 15 using std::string;
 16 using std::istream;
 17 using std::ostream;
 18 #define sz(c) (int)(c).size()
 19 #define all(c) (c).begin(), (c).end()
 20 #define iter(c) decltype((c).begin())
 21 #define cls(arr,val) memset(arr,val,sizeof(arr))
 22 #define cpresent(c, e) (find(all(c), (e)) != (c).end())
 23 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 24 #define fork(i, k, n) for (int i = (int)k; i <= (int)n; i++)
 25 #define tr(c, i) for (iter(c) i = (c).begin(); i != (c).end(); ++i)
 26 #define pb(e) push_back(e)
 27 #define mp(a, b) make_pair(a, b)
 28 struct BigN {
 29     typedef unsigned long long ull;
 30     static const int Max_N = 2010;
 31     int len, data[Max_N];
 32     BigN() { memset(data, 0, sizeof(data)), len = 0; }
 33     BigN(const int num) {
 34         memset(data, 0, sizeof(data));
 35         *this = num;
 36     }
 37     BigN(const char *num) {
 38         memset(data, 0, sizeof(data));
 39         *this = num;
 40     }
 41     void clear() { len = 0, memset(data, 0, sizeof(data)); }
 42     BigN& clean(){ while (len > 1 && !data[len - 1]) len--;  return *this; }
 43     string str() const {
 44         string res = "";
 45         for (int i = len - 1; ~i; i--) res += (char)(data[i] + '0');
 46         if (res == "") res = "0";
 47         res.reserve();
 48         return res;
 49     }
 50     BigN operator = (const int num) {
 51         int j = 0, i = num;
 52         do data[j++] = i % 10; while (i /= 10);
 53         len = j;
 54         return *this;
 55     }
 56     BigN operator = (const char *num) {
 57         len = strlen(num);
 58         for (int i = 0; i < len; i++) data[i] = num[len - i - 1] - '0';
 59         return *this;
 60     }
 61     BigN operator + (const BigN &x) const {
 62         BigN res;
 63         int n = max(len, x.len) + 1;
 64         for (int i = 0, g = 0; i < n; i++) {
 65             int c = data[i] + x.data[i] + g;
 66             res.data[res.len++] = c % 10;
 67             g = c / 10;
 68         }
 69         return res.clean();
 70     }
 71     BigN operator * (const BigN &x) const {
 72         BigN res;
 73         int n = x.len;
 74         res.len = n + len;
 75         for (int i = 0; i < len; i++) {
 76             for (int j = 0, g = 0; j < n; j++) {
 77                 res.data[i + j] += data[i] * x.data[j];
 78             }
 79         }
 80         for (int i = 0; i < res.len - 1; i++) {
 81             res.data[i + 1] += res.data[i] / 10;
 82             res.data[i] %= 10;
 83         }
 84         return res.clean();
 85     }
 86     BigN operator * (const int num) const {
 87         BigN res;
 88         res.len = len + 1;
 89         for (int i = 0, g = 0; i < len; i++) res.data[i] *= num;
 90         for (int i = 0; i < res.len - 1; i++) {
 91             res.data[i + 1] += res.data[i] / 10;
 92             res.data[i] %= 10;
 93         }
 94         return res.clean();
 95     }
 96     BigN operator - (const BigN &x) const {
 97         assert(x <= *this);
 98         BigN res;
 99         for (int i = 0, g = 0; i < len; i++) {
100             int c = data[i] - g;
101             if (i < x.len) c -= x.data[i];
102             if (c >= 0) g = 0;
103             else g = 1, c += 10;
104             res.data[res.len++] = c;
105         }
106         return res.clean();
107     }
108     BigN operator / (const BigN &x) const {
109         BigN res, f = 0;
110         for (int i = len - 1; ~i; i--) {
111             f *= 10;
112             f.data[0] = data[i];
113             while (f >= x) {
114                 f -= x;
115                 res.data[i]++;
116             }
117         }
118         res.len = len;
119         return res.clean();
120     }
121     BigN operator % (const BigN &x) {
122         BigN res = *this / x;
123         res = *this - res * x;
124         return res;
125     }
126     BigN operator += (const BigN &x) { return *this = *this + x; }
127     BigN operator *= (const BigN &x) { return *this = *this * x; }
128     BigN operator -= (const BigN &x) { return *this = *this - x; }
129     BigN operator /= (const BigN &x) { return *this = *this / x; }
130     BigN operator %= (const BigN &x) { return *this = *this % x; }
131     bool operator <  (const BigN &x) const {
132         if (len != x.len) return len < x.len;
133         for (int i = len - 1; ~i; i--) {
134             if (data[i] != x.data[i]) return data[i] < x.data[i];
135         }
136         return false;
137     }
138     bool operator >(const BigN &x) const { return x < *this; }
139     bool operator<=(const BigN &x) const { return !(x < *this); }
140     bool operator>=(const BigN &x) const { return !(*this < x); }
141     bool operator!=(const BigN &x) const { return x < *this || *this < x; }
142     bool operator==(const BigN &x) const { return !(x < *this) && !(x > *this); }
143     friend istream& operator >> (istream &in, BigN &x) {
144         string src;
145         in >> src;
146         x = src.c_str();
147         return in;
148     }
149     friend ostream& operator << (ostream &out, const BigN &x) {
150         out << x.str();
151         return out;
152     }
153 }A[5];
154 void solve(int n) {
155     fork(i, 1, 4) A[i] = 1;
156     if (n < 5) cout << A[n] << endl;
157     else {
158         int x = 1;
159         fork(i, 5, n) {
160             A[0] = A[1] + A[2] + A[3] + A[4];
161             A[x] = A[0];
162             if (++x == 5) x = 1;
163         }
164         cout << A[0] << endl;
165     }
166     rep(i, 5) A[i].clear();
167 }
168 int main() {
169 #ifdef LOCAL
170     freopen("in.txt", "r", stdin);
171     freopen("out.txt", "w+", stdout);
172 #endif
173     std::ios::sync_with_stdio(false);
174     int n;
175     while (cin >> n) {
176         solve(n);
177     }
178     return 0;
179 }
View Code

 

转载于:https://www.cnblogs.com/GadyPu/p/4574760.html

嵌入式系统开发笔记96:将STM32CubeIDE设置为中文 本文介绍将STM32CubeIDE设置为中文的方法。 阅读详情

相关推荐

基于YOLOv8和PaddlepaddleOCR的微信截图聊天记录提取

本文提出了一种基于YOLOv8和PaddleOCR的微信聊天记录提取方法。首先使用YOLOv8n模型分割出聊天气泡(针对深浅色模式分别训练),通过合成数据集增强模型鲁棒性,召回率达0.995。随后采用PP-OCRv5进行文本识别,利用坐标匹配将气泡内文本送入识别队列,短长文本平均置信度分别>0.98和>0.95。文中特别强调了PaddleOCR不同版本的输出格式差异及适配方案,建议使用3.0+版本。该方法有效解决了直接OCR识别易受干扰的问题,通过气泡分割+文本定位的两阶段策略显著提升了识别准确

2401_87383958的博客 2377

hdu 1250 Hat's Fibonacci

hdu   1250   Hat's Fibonacci               题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1250 题目大意:一个斐波纳契小变形,公式已给出。 题目分析:大数无坑,第一维N代表第几个此数列中的数,第二位中首位0存的是万进制下有多少位,后面就是万进制从低到高存下的数了。 code: #include #

slicer的技术交流栈 764

07- Rossmann商店销售预测 (Xgboost集成算法) (项目七)

Rossmann在欧洲国家经营着3000多家日化用品超市。目前,Rossmann商店经理的任务是提前6周预测他们的日销售额。商店的销售受到许多因素的影响,包括促销、竞争、学校和国家假日、季节性和地域性。由于数以千计的管理者根据自己的特殊情况预测销售,结果的准确性可能会有很大的差异。 因此使用机器学习算法对销量进行预测,Rossmann要求预测德国1115家商店的6周日销售额。可靠的销售预测使商店经理能够制定有效的员工时间表,提高生产力和积极性。

March_A的博客 2474

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

hdu 1250 Hat's Fibonacci(高精度数) // 继续大数,哎、、 Problem Description A Fibonacci sequence is calculated by adding the previous...

dilan3700的博客 194

OpenClaw与Ollama本地AI部署指南

AI模型本地化部署是当前企业数字化转型的关键技术,通过开源框架Ollama可以在消费级硬件上运行大语言模型。本文以OpenClaw多智能体系统为例,详解从环境配置到模型优化的全流程实践,特别针对国内开发者遇到的网络问题提供了镜像加速等解决方案。这种私有化部署方案尤其适合金融数据分析、企业知识管理等对数据安全要求高的场景,通过模块化设计实现多智能体协作,同时保持对NVIDIA显卡和普通CPU的兼容性。

weixin_34302561的博客 408

视觉-语言模型:BLIP与Flamingo如何理解图文?

视觉-语言模型:BLIP与Flamingo如何理解图文? ,人工智能,计算机视觉,大模型,AI,在当今人工智能飞速发展的时代,视觉 - 语言模型作为多模态领域的关键技术,正逐渐改变着我们与数字世界交互的方式。它们致力于打破图像与文本之间的模态壁垒,使计算机能够像人类一样,综合理解和处理视觉与语言信息。其中,BLIP 和 Flamingo 两款模型脱颖而出,以独特的架构和创新的训练方法,在图像描述生成、视觉问答、图文检索等任务中展现出卓越的性能。本文将深入剖析 BLIP 与 Flamingo 模型的工作原理。

不踩坑,不知道坑有多深;不总结,踩过的坑白踩。 4万+

hdu1250 Hat's Fibonacci

Hat's FibonacciTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 12633    Accepted Submission(s): 4241Problem DescriptionA Fibonacci sequence is c...

popcjz的博客 444

【AI大模型应用开发】【LangChain系列】实战案例6:利用大模型进行文本总结的方法探索,文本Token超限怎么办?

假设有一组文档(PDF、Notion页面、客户问题等),你想要总结内容。可以利用大模型来帮你。今天来系统看下利用大模型来对文本进行总结的方法,以LangChain的使用为例。

同学小张的博客 3750

HDU 1250 Hat's Fibonacci

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n

光明~~~ 3万+

微信小程序 - 详细实现打开跳转第三方 H5 网页链接,在微信小程序内直接跳转打开第三方网站链接详细教程(支持跳转公众号文章等,直接复制代码即可)

小程序跳转h5,小程序-Taro小程序中打开h5页面链接,...小程序跳转h5链接(web-view)_微信小程序,小程序如何跳转h5页面,小程序跳转到第三方H5网页,微信小程序跳转第三方H5的方法,小程序-实现怎么跳转打开H5网页链接(或跳转至公众号文章,打开第三方网站,放校验文件,怎么配置业务域名,校验文件验证域名,把校验文件放到对面网站,别人的服务器也打不开没权限怎么放呢,勾选不校验合法域名,txt,打不开别人的网页怎么办,真机调试打不开,无法跳转,有什么其他办法不放校验文件吗,后台配置,怎么

🏆 前端领域优质创作者 3万+

【红外技术】DDE算法:HE在红外图像可视化上的应用(附源码)

并且数据一般是以 8 的整数倍的位宽在电子系统中应用,因此大多数的显示器的显示位宽为 8bit,共 256 个灰阶。为了使红外图像可视化,因此需要一种“数据压缩”技术,还需要既可能的不丢失原始图像信息。HE后的图像直方图分布比较均匀离散,图像对比度好。但是HE算法只是适用某些图像,它是将灰度集中区域进行拉伸得到,也会放大该集中区域的噪声,它是一种“不公平”的映射。以下是红外细节增强算法的演示,很明显右边的图像,展现了更多的图像细节,对于小目标的观测非常友好。文章已于2019-12-02修改。

sunwindl91181的博客 950

hdu1250Hat's Fibonacci

题目链接 这道题的核心还是利用,大数+题目的fibonacci来做 代码如下: #pragma warning(disable:4996); #include <iostream> #include<stdio.h> #include<string.h> #include<algorithm> #include<queue> using ...

Roxannekkk的博客 240

AI时代的软件质量保证新方法论

3.2.1 质量保证的方法论 质量保证(Quality Assurance, QA)是一种系统化的方法,用于确保产品或服务符合预定的质量标准。在AI时代,软件质量保证的方法论需要适应不断变化的AI技术和应用场景。 3.2.1.1 质量管理体系的构建 首先,构建一个完善

AI天才研究院 1363

HDU1250--Hat's Fibonacci 第i个斐波那契数

HDU:HDU1250 求第i个斐波那契数问题: 总结: 数组尽量往大开,不要超内存。 不是很难。 import java.util.Scanner; import java.math.BigInteger; public class Main { public static void main(String[] args) { Scanner in = new Scanner(Syst...

匿名攻城狮 688

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

TMS_WebGMaps_1.9.8.0_Full_Source

TMS_WebGMaps_1.9.8.0_Full_Source 全源码 delphi cbuilder

hdu 1250 Hat's Fibonacci(java大数)

点击打开题目链接 Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7407    Accepted Submission(s): 2414 Problem Description

risker_2013的专栏 924

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU 1250 Hat's Fibonacci

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n

超 3040

大中型超市收银系统(可直接运行)

光步前台收银系统系统功能:商品销售、商品退货、挂单、收银员权限、会员销售、单品取消、整单取消、商品查询、脱机销售、脱机数据上传,基本资料下载,开钱箱、小票打印、收款结算,支持多币种付款方式(现金、储值卡、礼券、微信等),支持多种促销。运行环境:.net 4.0登陆信息用户名:1001 密码:123456内置商品信息,商品编码可输入00001000 - 00010000,测试效果相关功能键F5 结算 F9挂单 F11商品查询 F8退货 Insert单品取消 Del整单取消 F12开钱箱F2 会员 Ctrl+Z退出系统 Home 锁屏 相关源码待公开

HDU1250 Hat's Fibonacci

Hat's Fibonacci Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 7818    Accepted Submission(s): 2543 Problem Description A Fibonacci se

星尘 570

HDU1250 Hat's Fibonacci 【亿进制】

#include #include #define mod 1000000000 int arr[10001][230]; void Add(int i, int j) { for(int k = 0; k < 230; ++k) { arr[i][k] += arr[j][k]; if(arr[i][k] >= mod) { arr[i][k] -= mod; +

长风的专栏 1058

hdu1250-Hat's Fibonacci

http://acm.hdu.edu.cn/showproblem.php?pid=1250 二维大数处理 #include #include #include #include using namespace std ; #define maxm 10005 #define maxn 305 int fi[ maxm ][ maxn ] ; void Add() { memset(

luckycoding的专栏 887

hdu 1250 Hat's Fibonacci

Problem Description A Fibonacci sequence is calculated by adding the previous two members the sequence, with the first two members being both 1. F(1) = 1, F(2) = 1, F(3) = 1,F(4) = 1, F(n>4) = F(n

小周周i的博客 368

[大数] HDU 1250 - Hat's Fibonacci

一开始用int二维数组,MLE了。。然后改成char数组过了。

Freeway的博客 808
上一篇: hdu 2203 亲和串
下一篇: hdu 1212 Big Number
dong12276
博客等级 码龄13年 0粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值