山东省第七届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(最小公倍数)是很容易的事,现在我遇到了 ...
随机推荐
- CentOS下PHP7的编译安装,MySQL的支持和一些问题的解决
最近试了一下PHP7,在编译和支持MySQL上都遇到一些问题,相信不少同学也同样遇到,所以在这里聊一下这个过程.简单来讲编译PHP7只需要3步: 1../buildconf --force 2../c ...
- java 反射获取类的属性 类型 名称和值
/** * 获取属性类型(type),属性名(name),属性值(value)的map组成的list * */ private List getFiledsInfo(Object o){ Field[ ...
- SQL DELETE 语句
DELETE 语句用于删除表中的行. 语法 DELETE FROM 表名称 WHERE 列名称 = 值 Person: LastName FirstName Address City Gates Bi ...
- ansible 简单使用
前面讲完安装,现在说说怎么用 1.创建目录 mkdir -p /etc/ansible 2. 编辑(或创建)/etc/ansible/hosts 并在其中加入一个或多个远程系统:echo '192.1 ...
- sql执行
一.提高sql执行效率---in与exist . where column in (select * from table where ...) . ...where exists (select ' ...
- 视觉机器学习读书笔记--------BP学习
反向传播算法(Back-Propagtion Algorithm)即BP学习属于监督式学习算法,是非常重要的一种人工神经网络学习方法,常被用来训练前馈型多层感知器神经网络. 一.BP学习原理 1.前馈 ...
- cmd导入导出
2:用cmd进入命令行输入:tnsping cmstar就是测试172.18.13.200是否连接成功3:导入与导出,如下: 数据导出: 1 将数据库TEST完全导出,用户名system 密码mana ...
- java内存泄漏的定位与分析
1.为什么会发生内存泄漏 java 如何检测内在泄漏呢?我们需要一些工具进行检测,并发现内存泄漏问题,不然很容易发生down机问题. 编写java程序最为方便的地方就是我们不需要管理内存的分配和释放, ...
- Html5三维全景
先看DEMO:http://think.weiyingjia.cn/liuming/quanjing/out.html 准备: 1.一张或多张全景图片素材 2.pano2VR软件,链接:http ...
- js数字位数太大导致参数精度丢失问题
最近遇到个比较奇怪的问题,js函数里传参,传一个位数比较大,打印arguments可以看到传过来的参数已经改变. 然后查了一下,发现确实是js精度丢失造成的.我的解决方法是将数字型改成字符型传输,这样 ...