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. python笔记之bisect模块

    python笔记之bisect模块 当你决定使用二分搜索时,这个模块会给你带来很大的帮助. 例子 import bisect L = [1,3,3,6,8,12,15] x = 3 #在L中查找x,x ...

  2. X-factor Chains(POJ3421 素数)

    X-factor Chains Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6212   Accepted: 1928 D ...

  3. c# vs2010 winfrom控件检测网络环境

    写下以作备用,代码附上. public partial class UserControl1 : UserControl, IObjectSafety { //检测网络状态 [DllImport(&q ...

  4. javascript之尺寸,位置,溢出

    一.offsetWidth:元素的宽度,包括边框,内容,内边距. 二.offsetHeight:元素的高度,包括边框,内容,内边距. 三.offsetLeft:元素的X坐标(相对于最近已定位的祖先元素 ...

  5. 从Hello, world开始认识IL <第一篇>

    IL代码分析方法 Hello, world历史 .NET学习方法论 1.引言 1988年Brian W.Kernighan和Dennis M.Ritchie合著了软件史上的经典巨著<The C ...

  6. 你真的会玩SQL吗?Top和Apply

    原文:你真的会玩SQL吗?Top和Apply 本章预先想写一些Top和Apply基本的用法,但好像没什么意义,所以删掉了一些无用的东西,只留下几个示例,以保证系列的完整性. Top和Apply解决的常 ...

  7. ServerProperties

    Spring Boot 其默认是集成web容器的,启动方式由像普通Java程序一样,main函数入口启动.其内置Tomcat容器或Jetty容器,具体由配置来决定(默认Tomcat).当然你也可以将项 ...

  8. 2014第2周四部署环境&买火车票

    2014第2周四部署环境&买火车票 今天遇到mysql一个问题:要把两个包含不同数据库的绿色mysql安装包中的数据库文件合并到一个数据库中,之前在sqlserver下操作很简单,只需要分离. ...

  9. bzoj1643 [Usaco2007 Oct]Bessie's Secret Pasture 贝茜的秘密草坪

    Description 农夫约翰已经从他的牧场中取得了数不清块数的正方形草皮,草皮的边长总是整数(有时农夫约翰割草皮的刀法不合适,甚至切出了边长为0的正方形草皮),他已经把草皮放在了一个奶牛贝茜已经知 ...

  10. 静态链表实现 (A-B)U(B-A)

    图中黄色部分为(A-B)U(B-A)的实际意义,用结构数组做静态链表来实现该表达式 大致流程是先建立A链表,接着将挨个输入的B中元素在A链表中遍历.如果没找到,就加到A链表结尾下标为endpointe ...