山东省第七届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(最小公倍数)是很容易的事,现在我遇到了 ...
随机推荐
- iOS知识总结
mindNote文件下载地址 : 知识总结.zip
- JavaScript Array 常用函数整理
按字母顺序整理 索引 Array.prototype.concat() Array.prototype.filter() Array.prototype.indexOf() Array.prototy ...
- xmpp openfire smack 介绍和openfire安装及使用
前言 Java领域的即时通信的解决方案可以考虑openfire+spark+smack.当然也有其他的选择. Openfire是基于Jabber协议(XMPP)实现的即时通信服务器端版本,目前建议使用 ...
- C# 接口笔记
/* 1. 实现多态的两种方式. * 使用虚方法实现多态. * 使用抽象方法实现多态. * ...
- Oracle实战训练——ATM取款机业务
ATM取款机的数据库模拟开发和实战总结 一.ATM实战开发的简介. 学习了几天的Oracle,开始着手用数据库PL/SQL语言做一个简单的ATM取款机业务,主要是为了巩固数据库的知识,并非真正的去实现 ...
- 通过Request.Form获取同name的checkbox所有值
转自:http://www.cnblogs.com/Fred_Xu/archive/2013/01/16/how-to-get-the-checkbox-value-from-a-dynamicall ...
- RestTemplate配置
什么是RestTemplate? RestTemplate是Spring提供的用于访问Rest服务的客户端,RestTemplate提供了多种便捷访问远程Http服务的方法,能够大大提高客户端的编写效 ...
- JAVASE02-Unit07: 基本IO操作 、 文本数据IO操作
基本IO操作 . 文本数据IO操作 java标准IO(input/output)操作 package day07; import java.io.FileOutputStream; import ja ...
- CORS浏览器跨域
在SO上发现一个解释跨域很棒的,忍不住拿过来 链接在此:http://stackoverflow.com/questions/10636611/how-does-access-control-allo ...
- C++ 中的sort排序用法
STL中就自带了排序函数sortsort 对给定区间所有元素进行排序 要使用此函数只需用#include <algorithm> sort即可使用,语法描述为:sort(begin,end ...