How Many Fibs?

点我

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5158    Accepted Submission(s):
2007

Problem 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 100
1234567890 9876543210
0 0
 
Sample Output
5
4
 
思路很简单,但做得时候思维不严谨小的地方错了好多,一直在debug
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
#define len 10
int _cmp(char *a,char *b)
{
int i=,j,count=;
if(strlen(a)<strlen(b))
return ;
else if(strlen(a)>strlen(b))
return -;
else
{
char x[];
int j=,len1=strlen(a);
for(i=len1-;i>=;i--) /*倒置,全部都是高位在右,从右往左比较*/
x[j++]=a[i];
x[j]='\0';
i=len1-;
while(i>=)
{
if(b[i]>x[i])
return ;
else if(b[i]==x[i])
i--;
else
{
return -;
}
}
return ;
}
}
char f[][];
int main()
{
memset(f,'',sizeof(f));
int c,i,j,count,n;
char a[],b[];
f[][]='';
f[][]='';
for(i=;i<;i++)
{
c=;
for(j=;j<;j++)
{
f[i][j]=(f[i-][j]+f[i-][j]+c-*'')%len+'';
c=(f[i-][j]+f[i-][j]+c-*'')/len;
}
}
for(i=;i<;i++) /*变成字符串方便实用strlen()*/
for(j=;j>=;j--)
if(f[i][j]!='')
{
f[i][j+]='\0';
break;
}
while(cin>>a>>b)
{
if(a[]==''&&b[]=='')
break;
count=;
j=;
for(i=;i<=;i++)
{
if(_cmp(a,f[i])>=&&_cmp(b,f[i])<=)
count++;
if(_cmp(b,f[i])>=)
break;
}
cout<<count<<endl;
}
}

How Many Fibs?的更多相关文章

  1. How many Fibs?【sudt 2321】【大数的加法及其比较】

    How many Fibs? Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Recall the definition of t ...

  2. 数论 - 高精度Fibonacci数 --- UVa 10183 : How Many Fibs ?

    How many Fibs? Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn := f n ...

  3. hdu 1316 How Many Fibs?

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...

  4. 【HDOJ】1316 How Many Fibs?

    Java水了. import java.util.Scanner; import java.math.BigInteger; public class Main { public static voi ...

  5. HDOJ 1316 How Many Fibs?

    JAVA大数.... How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Jav ...

  6. hdu--1316--How Many Fibs?(java大数)

    How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. (compareTo) How Many Fibs hdu1316 && ZOJ1962

    How Many Fibs? Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  8. How many Fibs? POJ - 2413

    How many Fibs? POJ - 2413 高精模板 #include<cstdio> #include<cstring> #include<algorithm& ...

  9. SPOJ #536. How many Fibs

    Since number could be 10^100, we have to use large number processing method, in string. A simpler me ...

随机推荐

  1. POJ 1190 生日蛋糕(DFS)

    生日蛋糕 Time Limit: 1000MSMemory Limit: 10000KB64bit IO Format: %I64d & %I64u Submit Status Descrip ...

  2. 1007 Numerical Summation of a Series

    简单入门题.按照题目给的指导编程,算多少数要理解题意. #include <stdio.h> int main(){ int k,ssx; double x,psix; ;ssx<= ...

  3. mysql 在启动时配置文件的查找方式

    知识储备: 1.mysql在启动时会去多个地方找它的配置文件,当然啦这些也都是可以从帮助中找到的,问题在于我们要知道怎么找到对应的帮助才行啊 实战: [root@workstudio data]# m ...

  4. Maven的使用--Eclipse在线安装Maven插件m2e

    我使用的Eclipse版本是3.7(Indigo) 通过Eclipse的help选项,点击“Install New Software...”弹出安装对话框, 点击add按钮,在Location里输入h ...

  5. NOI十连测 第四测 T2

    思路:线段树套可持久化treap,可持久化treap我还是第一次听说.. 改题的时候没看数据范围..乱开数组T_T #include<algorithm> #include<cstd ...

  6. MFC与Qt的内存管理

    最近在做MFC向Qt的移植,在内存管理方面遇到了很头疼的问题,虽然不知道问题到底出在哪,先了解下这两个库的内存管理方式.于是转载两篇关于内存管理的文章. 一. Qt内存管理: 在Qt的程序中经常会看到 ...

  7. Asp.net MVC Web.config配置技巧

    一.视图引入命名空间的设置 之前经常写这样的代码,而且每个页面都要写: @model IEnumerable<MvcStart.Models.People_Model> 其实有一种很方便的 ...

  8. TextReader/TextWriter 的类

    TextReader以及TextWriter这两个类,非常有用,很多方法都接受它们作为参数. TextReader有两个子类: StringReader/StringWriter 用于读取字符串: S ...

  9. Django的安装配置和开发

    参考:<Django Web开发指南> Django的安装配置 1.https://www.djangoproject.com/download/下载Django-1.5.1.tar.gz ...

  10. Unity 4.6 uGUI的点击事件

    因为Unity 4.6刚刚发布,自带的uGUI功能的相关资料还不是很完善,今天刚装的Unity 4.6,想看一下uGUI是否好用,那么开始就今天的学习吧啊! 1,新建一个空的工程.