Problem Description

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.

Input

Multiple test cases, the first line is an integer T (T<=10000), indicating the number of test cases.

Each test case is a line with an integer N (1<=N<=109).

Output

One line per case. If the answer don’t exist, output “-1” (without quotes). Otherwise, your answer should be formatted as “N=f1+f2+…+fn”. N indicates the given number and f1, f2, … , fn indicating the Fibonacci numbers in ascending order. If there are multiple ways, you can output any of them.

Sample Input

4
5
6
7
100

Sample Output

5=5
6=1+5
7=2+5
100=3+8+89 题解:贪心求解,此题需要注意的是相邻的两个数不能选择;
#include<string.h>
#include<stdio.h>
#include<math.h>
using namespace std;
long long int arr[]={,,};
int main()
{ long long int i,j,a,b[],k,m,l,kk;
for(i=;i<=;i++)
arr[i]=arr[i-]+arr[i-];//先打下表
long long int count=;
while(scanf("%lld",&m)!=-)
{
for(kk=;kk<m;kk++){
scanf("%lld",&a);
k=;
l=;count=;int pp=;
for(i=;i>=;i-=)
{
pp=;
count+=arr[i];
if(count>a)
{
count-=arr[i];
pp=;
}
else if(count==a)
{
k=;
b[l++]=arr[i];
break;
}
else if(count<a)
b[l++]=arr[i];
if(pp==)
i++;//判断一下上一个数是否选择,若没选,下一个数可以选择
}
if(k==)
{
printf("%d=",a);
for(i=l-;i>=;i--)
{ if(i==)
printf("%lld\n",b[i]);
else
printf("%lld+",b[i]);
}
}
else
printf("-1\n");
}
}
return ;
}

HDU ACM Fibonacci的更多相关文章

  1. HDU 3117 Fibonacci Numbers(围绕四个租赁斐波那契,通过计++乘坐高速动力矩阵)

    HDU 3117 Fibonacci Numbers(斐波那契前后四位,打表+取对+矩阵高速幂) ACM 题目地址:HDU 3117 Fibonacci Numbers 题意:  求第n个斐波那契数的 ...

  2. hdu acm 1028 数字拆分Ignatius and the Princess III

    Ignatius and the Princess III Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K ...

  3. hdu 3117 Fibonacci Numbers 矩阵快速幂+公式

    斐波那契数列后四位可以用快速幂取模(模10000)算出.前四位要用公式推 HDU 3117 Fibonacci Numbers(矩阵快速幂+公式) f(n)=(((1+√5)/2)^n+((1-√5) ...

  4. ACM HDU 1021 Fibonacci Again

    #include<iostream> using namespace std; int main() { int n; while(cin>>n) { if((n+1)%4== ...

  5. hdu 4786 Fibonacci Tree (2013ACMICPC 成都站 F)

    http://acm.hdu.edu.cn/showproblem.php?pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others) ...

  6. hdu 1021 Fibonacci Again(找规律)

    http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Others ...

  7. HDU 4786 Fibonacci Tree 最小生成树

    Fibonacci Tree 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=4786 Description Coach Pang is intere ...

  8. hdu 1021 Fibonacci Again(变形的斐波那契)

    传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1021 Fibonacci Again Time Limit: 2000/1000 MS (Java/Ot ...

  9. HDU 4786 Fibonacci Tree(生成树,YY乱搞)

    http://acm.hdu.edu.cn/showproblem.php? pid=4786 Fibonacci Tree Time Limit: 4000/2000 MS (Java/Others ...

随机推荐

  1. DRF 权限的流程

    DRF 权限的流程 django rest framework,入口是 dispatch,然后依次 --->>封装请求--->>处理版本--->>>认证--- ...

  2. Near Field Communication (NFC) applications

    Near Field Communication (NFC) applications There has been little practical guidance available on NF ...

  3. golang包快速生成base64验证码

    base64Captcha快速生成base64编码图片验证码字符串 支持多种样式,算术,数字,字母,混合模式,语音模式. Base64是网络上最常见的用于传输8Bit字节代码的编码方式之一.Base6 ...

  4. java如何填写简历?(干货篇)

        化身孤岛的鲸不才 - 十三夜之月 一份优秀的简历不一定能帮你找到一份满意的工作,但能大大提升你的面试机会. 不容否认,简历是对你的能力.教育和经历的一份简要信息概述. 简历中应该突出你最核心的 ...

  5. HDU3507Print Article (斜率优化DP)

    Zero has an old printer that doesn't work well sometimes. As it is antique, he still like to use it ...

  6. Django之mysql表单操作

    在Django之ORM模型中总结过django下mysql表的创建操作,接下来总结mysql表记录操作,包括表记录的增.删.改.查. 1. 添加表记录 class UserInfo(models.Mo ...

  7. bzoj 3052 糖果公园

    Written with StackEdit. Description \(Candyland\) 有一座糖果公园,公园里不仅有美丽的风景.好玩的游乐项目,还有许多免费糖果的发放点,这引来了许多贪吃的 ...

  8. nmap 扫描工具

    Nmap 7.30 ( https://nmap.org ) 使用方法: nmap [扫描类型(s)] [选项] {目标说明}目标说明:通过主机名称, IP 地址, 网段, 等等.协议: scanme ...

  9. 浅谈如何在SQL Server中生成脚本

    在生成脚本过程中,有很多参数可以选择,合理的配置这些参数,可以让我们很方便的按照我们的期望生成脚本. 生成脚本的一些选项,如下图: 我这里是SQL 2005 的选项, SQL 2008 的选项跟这个稍 ...

  10. SCARA——OpenGL入门学习一、二

    参考博客:http://www.cppblog.com/doing5552/archive/2009/01/08/71532.html 简介 最近开始一个机械手臂的安装调试,平面关节型机器人又称SCA ...