题目大意:

问[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. C语言程序代写(Linux下线程)

    联系QQ:928900200 CSCI 3120 Operating Systems Summer 2014 Handout 3Assignment 2Date Due: June 5, 2014 b ...

  2. javascript于boolean类型转换,运营商&amp;&amp;和|| 返回值

    javascript它是弱类型语言,不管是什么类型的数据可以被转换成boolean种类.转换规则如下面的: 数据类型                 转换为boolean后的值 NAN         ...

  3. bootstarp modal自己主动调整宽度的JS代码

    $('#ajaxPage').modal('show').css({ width: 'auto', 'margin-left': function () { return -($(this).widt ...

  4. ExtJs迄今datefield控制设置默认值

    假设extjs4 datefield日期控件设置默认值.为当天的前一月,和后一月 Ext.Date.MONTH      月 Ext.Date.YEAR         年 Ext.Date.DAY  ...

  5. 我不知道你是在一个多线程out该--【ITOO】

    仍向系统负载作出太慢.卡而发愁太?我不知道多线程,你们out该.最近花了大约两三天.多-threaded.通过团队的交流,多线程有更深入的思考.希望可以加入ITOO目里面,优化一下系统性能. 概念 线 ...

  6. POJ--2923--Relocation--如压力DP

    Relocation Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2288   Accepted: 950 Descrip ...

  7. datagrid直接编辑保存“设计缺陷”

    当今使用easyUI的datagrid组件的时候,碰到了一些问题,记录下来以便下次高速解决. 需求是在一张表单里会关联有一个列表,能够增删查改 曾经没用easyUI的时候,这个增和改的页面我通常是用一 ...

  8. iOS 7 新特性

      iOS7更新了很多引人注目的功能.用户界面完全重新设计了.iOS7为开发2D,2.5D游戏引入了全新的动画系统.加强多线程,点对点连接,以及许多其他重要的功能让iOS7成为有史以来最有意义的一次发 ...

  9. 排序算法门外汉理解-Shell排序

    #include <stdio.h> /* 希尔排序 基本思想:希尔排序又称为缩小增量排序,对简单插入排序的优化. (外部分组gap,组内部插入排序! ! ) 特点:一种不稳定的排序 */ ...

  10. ComboBox 自动调整组合框下拉部分的宽度

    /// <summary>        /// ComboBox 自动调整组合框下拉部分的宽度        /// </summary>        void Resiz ...