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. C语言编译过程简介

    刚开始接触编程的时候,只知道照书敲敲代码,一直都不知道为什么在windows平台下代码经过鼠标那样点击几下,程序的结果就会在那个黑色的屏幕上.现在找了个机会将C语言的编译原理做一下小小的总结,这样也能 ...

  2. CSS之Hack

    一.类内部Hack IE都能识别*;标准浏览器(如FF)不能识别*:IE6能识别*,但不能识别 !important, IE7能识别*,也能识别!important; FF不能识别*,但能识别!imp ...

  3. Eclipse IDE for Java EE Developers使用和新建工程helloworld

    开发j2ee还是用专门的java ee eclipse,自带了许多开发j2ee的插件,包括: This package includes: Data Tools Platform Eclipse Gi ...

  4. POJ 1195 Mobile phones (二维树状数组或线段树)

    偶然发现这题还没A掉............速速解决了............. 树状数组和线段树比较下,线段树是在是太冗余了,以后能用树状数组还是尽量用......... #include < ...

  5. UESTC_秋实大哥与家 2015 UESTC Training for Data Structures<Problem E>

    E - 秋实大哥与家 Time Limit: 3000/1000MS (Java/Others)     Memory Limit: 65535/65535KB (Java/Others) Submi ...

  6. poj 1020 Anniversary Cake(切正方形蛋糕+搜索)

                                                                                                         ...

  7. apache FtpServer 整合spring部署

    我们在项目中可能会出现这样的需求,使用ftp上传很大的文件后对需要对文件进行相应的逻辑处理,这时我们可以使用apache ftpServer来处理这段逻辑,只要我们做相应的部署和编写我们的逻辑代码,这 ...

  8. Ubuntu学习-简单指令

    查看是否安装了中文支持 locale -a 如果有 zh_CN.utf8 则表示系统已经安装了中文locale,如果没有则需要安装相应的软件包. 软件管理 apt ( Advanced Packagi ...

  9. magento后台登陆后,没任何提示,又跳转到登陆页面

    这个问题通常是cookie配置的问题.需要去将core_config_data中web/cookie/cookie_path.web/cookie/cookie_domain设为null

  10. freemarker声明变量

    freemarker声明变量 1.使用assign创建和替换变量 (1)新建声明变量的ftl variable.ftl: <html> <head> <meta http ...