zoukankan      html  css  js  c++  java
  • 第七届 山东省ACM Fibonacci(暴力)

    Fibonacci

    Time Limit: 2000MS Memory Limit: 131072KB

    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.

    Example Input

    4567100

    Example Output

    5=56=1+57=2+5100=3+8+89

    Hint

     

    Author

     “浪潮杯”山东省第七届ACM大学生程序设计竞赛

    题意:判断所给的数能不能由斐波那契数组成,如果能输出任意一种组成形式,不能输出-1

    #include <stdio.h>
    long long  num[10000];
    long long count[100];
    int main (){
    	num[1]=1;
    	num[2]=2;
    	for (int i=3;i<=50;i++){
    		num[i]=num[i-1]+num[i-2];
    	}
    	int n;
    	scanf ("%d",&n);
    	while (n--){
    		long long T;
    		scanf("%lld",&T);
    		int k=0;
    		long long c=T;
    		for(int i=50;i>=0;i--){
    			if (num[i]<=T&&T){
    				count[k++]=num[i];
    				T=T-num[i];
    			}
    		} 
    		if (!T){
    			printf ("%lld=",c);
    			for (int i=k-1;i>0;i--){
    				printf ("%lld+",count[i]);
    			}
    			printf ("%lld
    ",count[0]);
    		}
    		else{
    			printf ("-1");
    		}
    		
    		
    	} 
    	
    	return 0;
    } 




  • 相关阅读:
    Python使用selenium(二)
    自动化测试
    测试要求
    测试用例编写
    求职杂谈
    不会交谈的测试员,果然不是一个好的测试员
    浅谈微信小程序测试
    python 匿名函数lambda的用法
    python __xx__的定义和用处
    看django的感受
  • 原文地址:https://www.cnblogs.com/zswbky/p/6717885.html
Copyright © 2011-2022 走看看