山东省第七届ACM省赛------Fibonacci
Fibonacci
Time Limit: 2000MS Memory limit: 131072K
题目描述
Fibonacci numbers are well-known as follow:
Now given an integer N, please find out whether N can be represented as the sum of several Fibonacci numbers in such a way that the sum does not include any two consecutive Fibonacci numbers.
输入
Each test case is a line with an integer N (1<=N<=109).
输出
order. If there are multiple ways, you can output any of them.
示例输入
4
5
6
7
100
示例输出
5=5
6=1+5
7=2+5
100=3+8+89
来源
题意

#include<stdio.h> #include<iostream> #include<math.h> #include<string.h> using namespace std; int a[46]= {1,1}; int b[46]; void init() { for(int i=2; i<46; i++) a[i]=a[i-1]+a[i-2]; } int find(int n) { for(int i=1; i<46; i++) if(a[i]>n)return a[i-1]; return 0; } int main() { init(); int N; cin>>N; while(N--) { int n; cin>>n; int s=0,j=0; memset(b,0,sizeof(b)); while(s!=n) { int d=find(n-s); b[j++]=d; s+=find(n-s); } printf("%d=%d",n,b[--j]); for(--j; j>=0; j--) printf("+%d",b[j]); printf("\n"); } }
山东省第七届ACM省赛------Fibonacci的更多相关文章
- 山东省第七届ACM省赛------Memory Leak
Memory Leak Time Limit: 2000MS Memory limit: 131072K 题目描述 Memory Leak is a well-known kind of bug in ...
- 山东省第七届ACM省赛------Reversed Words
Reversed Words Time Limit: 2000MS Memory limit: 131072K 题目描述 Some aliens are learning English. They ...
- 山东省第七届ACM省赛------Triple Nim
Triple Nim Time Limit: 2000MS Memory limit: 65536K 题目描述 Alice and Bob are always playing all kinds o ...
- 山东省第七届ACM省赛------The Binding of Isaac
The Binding of Isaac Time Limit: 2000MS Memory limit: 65536K 题目描述 Ok, now I will introduce this game ...
- 山东省第七届ACM省赛------Julyed
Julyed Time Limit: 2000MS Memory limit: 65536K 题目描述 Julyed is preparing for her CET-6. She has N wor ...
- 山东省第七届ACM省赛
ID Title Hint A Julyed 无 B Fibonacci 打表 C Proxy 最短路径 D Swiss-system tournament 归并排序 E The Binding of ...
- 山东省第十届ACM省赛参赛后的学期总结
5.11,5.12两天的济南之旅结束了,我也参加了人生中第一次正式的acm比赛,虽然是以友情队的身份,但是我依旧十分兴奋. 其实一直想写博客来增加自己的能力的,但是一直拖到现在,正赶上老师要求写一份总 ...
- Rectangles(第七届ACM省赛原题+最长上升子序列)
题目链接: http://acm.nyist.edu.cn/JudgeOnline/problem.php?pid=1255 描述 Given N (4 <= N <= 100) rec ...
- 山东理工大学第七届ACM校赛-LCM的个数 分类: 比赛 2015-06-26 10:37 18人阅读 评论(0) 收藏
LCM的个数 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 对于我们来说求两个数的LCM(最小公倍数)是很容易的事,现在我遇到了 ...
随机推荐
- FireDAC 连接SQL Server一些要注意的地方
TFDConnection: FetchOptions.Mode 设置为fmAll, 返回全部结果, 否则默认只返回前50条, 效果与open以后再执行FetchAll一样 Specifies how ...
- 用js加密你的重要信息
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- 给定一个double类型的数组arr,其中的元素可正可负可0,返回子数组累乘的最大乘积。例如arr=[-2.5,4,0,3,0.5,8,-1],子数组[3,0.5,8]累乘可以获得最大的乘积12,所以返回12。
分析,是一个dp的题目, 设f[i]表示以i为结尾的最大值,g[i]表示以i结尾的最小值,那么 f[i+1] = max{f[i]*arr[i+1], g[i]*arr[i+1],arr[i+1]} ...
- ax Mail
SysMailer mailer = new SysMailer(); SysEmailParameters parameters = SysEmailParameters::find(); ; tr ...
- SqList *L 和 SqList * &L的区别/学习数据结构突然发现不太懂 小祥我查找总结了一下
小祥在学习李春葆的数据结构教程时发现一个小问题,建立顺序表和输出线性表,这两个函数的形参是不一样的. 代码在这里↓↓↓ //定义顺序表L的结构体 typedef struct { Elemtype d ...
- LeetCode Find the Celebrity
原题链接在这里:https://leetcode.com/problems/find-the-celebrity/ 题目: Suppose you are at a party with n peop ...
- jar包目录下MANIFEST.MF标准格式
jar包目录格式: |-- com | |-- test.class |-- META-INF | |-- MAINFEST.MF 一个正常的jar包下必有META-INF/MANIFEST.MF清单 ...
- vim - char code and charset
In normal mode, type ga to display the decimal and hex values for the character under the cursor, or ...
- Myeclipse8.6配置android_SDK,进行android开发(转载)
Myeclipse8.6下部署环境,总结一下个人Android环境配置的过程(首先不要急着启动Myeclipse) 1.下载SDK:http://developer.android.com/sdk/i ...
- Abundant Resources
https://github.com/vhf/free-programming-books/blob/master/free-programming-books-zh.md