hdu 1316 How Many Fibs? (模拟高精度)
题目大意:
问[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? (模拟高精度)的更多相关文章
- hdu 1316 How Many Fibs?
题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=1316 How Many Fibs? Description Recall the definition ...
- hdu 1316 How many Fibs?(高精度斐波那契数)
// 大数继续 Problem Description Recall the definition of the Fibonacci numbers: f1 := 1 f2 := 2 fn : ...
- HDU 1316 How Many Fibs?(java,简单题,大数)
题目 /** * compareTo:根据该数值是小于.等于.或大于 val 返回 -1.0 或 1: public int compareTo(BigInteger val) 将此 BigInteg ...
- HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011亚洲北京赛区网络赛)
HDU 4041 Eliminate Witches! (模拟题 ACM ICPC 2011 亚洲北京赛区网络赛题目) Eliminate Witches! Time Limit: 2000/1000 ...
- HDU 1002 - A + B Problem II - [高精度]
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1002 Problem DescriptionI have a very simple problem ...
- HDU 5948 Thickest Burger 【模拟】 (2016ACM/ICPC亚洲区沈阳站)
Thickest Burger Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)T ...
- HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
Ugly Problem Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Tota ...
- 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 ...
- HDU 4814 Golden Radio Base 模拟
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4814 题目大意: 把一个正整数表示为φ进制, φ = (1+√5)/2 . 且已知: 1. φ + 1 ...
随机推荐
- android EditText的美化
今天要做一个页面,有EditText,于是就搞起了它的美化. EditText的美化,我的第一反应是,在EditText的左边设置显示一张图片,这样会比較好看. 设置左边显示图片的属性为:androi ...
- Linux 编程学习笔记----ANSI C 文件I/O管理
转载请注明出处:http://blog.csdn.net/suool/article/details/38129201 问题引入 文件的种类 依据数据存储的方式不同,能够将文件分为文本文件和二进制文件 ...
- 看PHP在内部迭代的动作
以下我们来了解怎样实现一个自己定义的迭代器,然后再開始慢慢理解迭代器的内部工作原理.先来看一个官方的样例: <? php class myIterator implements Iterator ...
- 重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush
原文:重新想象 Windows 8 Store Apps (18) - 绘图: Shape, Path, Stroke, Brush [源码下载] 重新想象 Windows 8 Store Apps ...
- C#改动文件或目录的权限,为指定用户、用户组加入全然控制权限
C#改动文件或文件夹的权限,为指定用户.用户组加入全然控制权限 //给Excel文件加入"Everyone,Users"用户组的全然控制权限 FileInfo fi = new F ...
- POJ - 3249 Test for Job (DAG+topsort)
Description Mr.Dog was fired by his company. In order to support his family, he must find a new job ...
- [MSSQL]最小公约数
[摘要]一个朋友在展BOM的时候有这种需求,两列字段(数值):A ,B A=用量,B=底数,组成用量=用量/底数.A/B,若能被整除,显示整除的结果,若不能整除显示分数形式A/B(分数形式要是约分 ...
- 系统负载测试工具-LoadRunner
LoadRunner的主要作用是对系统压力测试进行分析 与之相类似的工具是:badboy:录制脚本工具+jmeter:分析结果工具
- HDU 1874 畅通公程续 (最短路 水)
Problem Description 某省自从实行了非常多年的畅通project计划后,最终修建了非常多路.只是路多了也不好,每次要从一个城镇到还有一个城镇时,都有很多种道路方案能够选择,而某些方案 ...
- [LeetCode61]Rotate List
题目: Given a list, rotate the list to the right by k places, where k is non-negative. For example:Giv ...