博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2413 How many Fibs?
阅读量:2443 次
发布时间:2019-05-10

本文共 1364 字,大约阅读时间需要 4 分钟。

How many Fibs?
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 10748   Accepted: 3982

Description

Recall the definition of the Fibonacci numbers: 
f1 := 1 f2 := 2 fn := fn-1 + fn-2     (n>=3)
Given two numbers a and b, calculate how many Fibonacci numbers are in the range [a,b].

Input

The input contains several test cases. Each test case consists of two non-negative integer numbers a and b. Input is terminated by a=b=0. Otherwise, a<=b<=10
100. The numbers a and b are given with no superfluous leading zeros.

Output

For each test case output on a single line the number of Fibonacci numbers fi with a<=fi<=b.

Sample Input

10 1001234567890 98765432100 0

Sample Output

54

解题思路:

用一个字符串数组记录位数小于101的所有fibs,然后对于给定的a,b,求出满足条件的个数;

#include 
#include
#include
using namespace std;char fibs[10005][102];void add(int n){ int len_a=strlen(fibs[n-1]),len_b=strlen(fibs[n-2]); int p=len_a-1,q=len_b-1; int a[102],left=0; for (int i=0;i<102;i++){ a[i]=left; if (p>=0) a[i]+=fibs[n-1][p--]-'0'; if (q>=0) a[i]+=fibs[n-2][q--]-'0'; left=a[i]/10; a[i]%=10; } int i; for (i=101;i>=0;i--){ if (a[i]!=0) break; } int k=0; while (i>=0){ fibs[n][k++]=a[i--]+'0'; } fibs[n][k]=0;}bool cmp(char *a,char *b){ int len_a=strlen(a),len_b=strlen(b); if (len_a>len_b) return true; if (len_a
b[n]-'0') return true; if (a[n]-'0'

转载地址:http://kfbqb.baihongyu.com/

你可能感兴趣的文章
source命令的一个妙用(转)
查看>>
亚洲开源航母呼之欲出 目标瞄向Novell与红帽(转)
查看>>
正版化:水到渠成?预装Windows对Linux无打压(转)
查看>>
Red Hat并购JBoss 谁将受创?(转)
查看>>
基于IBM大型主机,Linux开辟意大利旅游新天地(转)
查看>>
一些Linux试题(经典!!)(转)
查看>>
优化MySQL数据库性能的八大“妙手”(转)
查看>>
小心:谁动了你的注册表(转)
查看>>
Unix/BSD/Linux的口令机制初探(转)
查看>>
福布斯:Sun下场本可避免 老CEO不听劝(转)
查看>>
清华紫光笔记本和PC电脑预装LINUX操作平台(转)
查看>>
根据什么选择一套适合自己的linux系统?(转)
查看>>
新型威盛电脑处理器亮相国内市场(转)
查看>>
戴尔将在法国推出Linux笔记本(转)
查看>>
近9成盗版Office用户称愿投奔开源(转)
查看>>
MySQL购InnoDB不敌甲骨文宣布开放数据引擎(转)
查看>>
银行监会选红旗Linux建设公文传输系统(转)
查看>>
红旗支撑国家外汇管理局网上核销系统(转)
查看>>
实例讲解密码破解以及抗击手段介绍(转)
查看>>
网上交易中帐号和密码被盗的解决途径(转)
查看>>