题目大意:

问[s,e]之间有多少个 斐波那契数。

思路分析:

直接模拟高精度字符串的加法和大小的比較。

注意wa点再 s 能够从 0 開始

那么要在推断输入结束的时候注意一下。

#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm> using namespace std; struct node
{
char str[111];
int len; void print()
{
for(int i=len-1; i>=0; i--)
{
printf("%c",str[i]);
}
puts("");
} } fib[1500]; node operator + (const node &a,const node &b)
{
node c;
for(int i=0; i<=110; i++)c.str[i]='0';
for(int i=0; i<max(a.len,b.len); i++)
{
int dig=c.str[i]-'0'+a.str[i]-'0'+b.str[i]-'0';
int s=0;
if(dig>=10)
{
dig-=10;
s++;
}
c.str[i]=dig+'0';
if(s)c.str[i+1]='1';
}
for(c.len=110; c.str[c.len]=='0' ; c.len--);
c.len++;
return c;
}
bool operator <= (node &a,node &b)
{
if(a.len!=b.len)return a.len<b.len;
else
{
for(int i=a.len-1; i>=0; i--)
{
if(a.str[i]>b.str[i])
return false;
else if(a.str[i]<b.str[i])
return true;
}
return true;
}
} bool operator < (node &a,node &b)
{
if(a.len!=b.len)return a.len<b.len;
else
{
bool is=true; for(int i=0; i<a.len; i++)
if(a.str[i]!=b.str[i])is=false; for(int i=a.len-1; i>=0 && !is; i--)
{
if(a.str[i]>b.str[i])
return false;
else if(a.str[i]<b.str[i])
return true;
}
return !is;
}
} int main()
{
fib[1].len=1;
fib[1].str[0]='1';
fib[2].len=1;
fib[2].str[0]='2';
for(int i=3;; i++)
{
fib[i]=fib[i-1]+fib[i-2];
if(fib[i].len>101)break;
} node s,e;
while(scanf("%s%s",s.str,e.str)!=EOF)
{
if(s.str[0]=='0' && e.str[0]=='0')break;
s.len=strlen(s.str);
e.len=strlen(e.str);
reverse(s.str,s.str+s.len);
reverse(e.str,e.str+e.len);
int i=1,st,ed;
while(fib[i]<s)i++;
st=i;
while(fib[i]<=e)i++;
ed=i;
printf("%d\n",ed-st);
}
return 0;
}

hdu 1316 How Many Fibs? (模拟高精度)的更多相关文章

  1. hdu 1316 How Many Fibs?

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

  2. hdu 1316 How many Fibs?(高精度斐波那契数)

    //  大数继续 Problem Description Recall the definition of the Fibonacci numbers:  f1 := 1  f2 := 2  fn : ...

  3. HDU 1316 How Many Fibs?(java,简单题,大数)

    题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...

  4. HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)

    HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...

  5. HDU 1002 - A + B Problem II - [高精度]

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...

  6. HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)

    Thickest Burger Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)T ...

  7. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))

    Ugly Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tota ...

  8. HDU 5873 Football Games 【模拟】 (2016 ACM/ICPC Asia Regional Dalian Online)

    Football Games Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)To ...

  9. HDU 4814 Golden Radio Base 模拟

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题目大意: 把一个正整数表示为φ进制, φ = (1+√5)/2 . 且已知: 1. φ + 1 ...

随机推荐

  1. Codeforces 107B Basketball Team 简单概率

    题目链接:点击打开链接 题意: 给定n m h 表示有m个部门,有个人如今在部门h 以下m个数字表示每一个部门的人数.(包含他自己) 在这些人中随机挑选n个人,问挑出的人中存在和这个人同部门的概率是多 ...

  2. Bash ShellShock 解决办法

    2014 年 9 月 24 日,Bash 惊爆严重安全漏洞,编号为 CVE-2014-6271,该漏洞将导致远程攻击者在受影响的系统上执行任意代码.GNU Bash 是一个为 GNU 计划编写的 Un ...

  3. javascript---在自由落体实现

    实现一些简单的物业自由落体需要理解: clientHeight:浏览器客户机的整体高度 offsetHeight:物(实例div)高低 offsetTop:从对象client最顶层的距离 简单demo ...

  4. 表白程序源代码,android

    弄了一个表白程序,还是不错的,内容能够自己设置.并附上源代码:http://download.csdn.net/detail/a358763471/7803571 看下效果图吧.是动画的哦...

  5. Perl中的单行凝视和多行凝视

    同其它大多数编程语言一样.Perl中的单行凝视也是#开头.比如: #print "Hello,World!"; 但多行凝视.不同的语言有不同的凝视方式,比方说: Java,C/C+ ...

  6. char与unsigned char 差别

    char 与 unsigned char的本质差别 http://bbs.csdn.net/topics/270080484 同一个内存内容:10010000      你用char*   解释是-1 ...

  7. OPhone SDK初体验

    OPhone SDK初体验 write by 九天雁翎(JTianLing) -- blog.csdn.net/vagrxie 讨论新闻组及文件 背景说明 中国伟大的垄断龙头,世界上也是顶尖的中移动最 ...

  8. Directx11学习笔记【十七】纹理贴图

    本文由zhangbaochong原创,转载请注明出处http://www.cnblogs.com/zhangbaochong/p/5596180.html 在之前的例子中,我们实现了光照和材质使得场景 ...

  9. resharper 设置代码颜色

  10. yate.conf

    但档案.粘贴下面的例子.不解释!除去非常灵活!只保留sip电话! [general] ; General settings for the operation of Yate ; modload: b ...