- 浏览: 36006 次
文章分类
- 全部博客 (41)
- 卧鸟个去 (2)
- Transform (2)
- Mathmatic (9)
- Plant-Tree (7)
- Data-Struct (12)
- Red-Black-Tree (1)
- Radix-Tree (1)
- Trie (2)
- String (4)
- BST (2)
- Amazing-Union-Find-Set (1)
- HDU (27)
- OJ (32)
- BFS (3)
- Pretty-Suffix-Array (2)
- POJ (6)
- Graceful-Segment-Tree (2)
- Geometry (6)
- Priority-Queue (2)
- Dynamic-Programing (1)
- DP (3)
- LCS (1)
- Convex-Hull (2)
- Triangulation (1)
- DFS (3)
- Combinatorial-Mathematics (2)
- Big-Number (1)
- Statistic (3)
- STL (1)
- Shortest-Path (3)
- ZOJ (1)
- Leftist-Tree (1)
- Prime (1)
- Binary-Index-Tree (1)
- (1)
- Stack (1)
- SPFA (0)
- CRT (1)
How Many Fibs?
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 1212 Accepted Submission(s): 501
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].
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
Source
Recommend
Eddy
听到KID既大数题目题目推荐!我都用STL写左一个有加法重载既大数类。
不过令我WA多次既问题竟然系读错题目{= =b},f2 = 1,结果WA多次,真系…………
下面直接贴代码:
4281094 | 2011-07-28 20:00:08 | Accepted | 1316 | 156MS | 416K | 2614 B | C++ | 10SGetEternal{(。)(。)}! |
#include <iostream> #include <string> #include <vector> using namespace std; #define MAXI 486 class Bnum { public : vector<int> n; int l; Bnum(string str = "0") { int i; l = str.length(); n.resize(l); for (i = 0; i < l; i++) n[i] = str[l - i - 1] - 48; } Bnum & operator = (Bnum &o) { l = o.l; n = o.n; return o; } friend Bnum operator + (Bnum a, Bnum b) { Bnum c; int i, len = a.l > b.l? a.l: b.l; c.l = len + 1; c.n.resize(c.l); a.n.resize(c.l); b.n.resize(c.l); for (c.n[len] = i = 0; i < len; i++) { c.n[i] += a.n[i] + b.n[i]; c.n[i + 1] = c.n[i] / 10; c.n[i] %= 10; } if (!c.n[c.l - 1]) c.n.resize(--c.l); return c; } friend bool operator < (Bnum a, Bnum b) { int i; if (a.l == b.l) { for (i = a.l - 1; i >= 0; i--) if (a.n[i] < b.n[i]) return 1; else if (a.n[i] > b.n[i]) return 0; return 0; } else return a.l < b.l; } friend bool operator > (Bnum a, Bnum b) { int i; if (a.l == b.l) { for (i = a.l - 1; i >= 0; i--) if (a.n[i] > b.n[i]) return 1; else if (a.n[i] < b.n[i]) return 0; return 0; } else return a.l > b.l; } friend bool operator == (Bnum a, Bnum b) { int i; if (a.l == b.l) { for (i = a.l - 1; i >= 0; i--) if (a.n[i] != b.n[i]) return 0; return 1; } else return 0; } friend bool operator <= (Bnum a, Bnum b) { return a == b || a < b; } friend bool operator >= (Bnum a, Bnum b) { return a == b || a > b; } friend ostream & operator << (ostream & output, Bnum &o) { int i; for (i = 0; i < o.l; i++) output << o.n[o.l - i - 1]; return output; } friend istream & operator >> (istream & input, Bnum &o) { string buf; input >> buf; o = Bnum(buf); return input; } }fin[MAXI]; void init() { int i; fin[1] = Bnum("1"); fin[2] = Bnum("2"); for (i = 3;; i++) if (fin[i - 1].l >= 102) break; else fin[i] = fin[i - 1] + fin[i - 2]; } int main() { int i, sum; Bnum a, b; init(); while (cin >> a >> b) { if (a == Bnum("0") && b == Bnum("0")) break; for (sum = 0, i = 1; i < MAXI; i++) if (fin[i] > b) break; else if (a <= fin[i] && fin[i] <= b) sum++; cout << sum << endl; } return 0; }
下面贴上K神关于呢个题目既博文!!!
发表评论
-
HDU 1370 Biorhythms
2011-08-03 10:27 1150Biorhythms Time Limit: 2000/10 ... -
HDU 1075 What Are You Talking About
2011-08-04 11:00 834What Are You Talking About Tim ... -
HDU 1058 Humble Numbers
2011-08-02 15:55 1170Humble Numbers Time Limit: 200 ... -
HDU 2095 find your present (2)
2011-08-02 16:13 766find your present (2) Time Lim ... -
HDU 1022 Train Problem I
2011-08-02 21:00 995Train Problem I Time Limit: 20 ... -
2142 HDU box
2011-08-02 21:21 735box Time Limit: 3000/1000 MS ( ... -
HDU 2151 Worm
2011-08-01 20:48 787Worm Time Limit: 1000/1000 MS ... -
HDU 2722 Here We Go(relians) Again
2011-08-02 00:06 968Here We Go(relians) Again Time ... -
HDU 3791 二叉搜索树
2011-08-02 14:26 1160二叉搜索树 Time Limit: 20 ... -
PKU 2352 Stars
2011-07-31 21:47 985Stars Time Limit: 1000MS ... -
PKU 2774 Long Long Message
2011-07-31 21:26 864Long Long Message Time Li ... -
PKU 2777 Count Color
2011-07-31 21:31 767Count Color Time Limit: 1 ... -
HDU 2098 分拆素数和
2011-07-31 21:08 1015分拆素数和 Time Limit: 1000/1000 MS ... -
ZOJ 3512 Financial Fraud .
2011-07-31 20:49 1230Financial Fraud Time Limit: 3 ... -
HDU 1798 Tell me the area .
2011-07-31 20:47 1070Tell me the area Time Limit: 3 ... -
HDU 2962 Trucking .
2011-07-31 20:46 640Trucking Time Limit: 20000/100 ... -
HDU 1596 find the safest road .
2011-07-31 20:45 571find the safest road Time Limi ... -
HDU 2553 N皇后问题 .
2011-07-31 20:20 661N皇后问题 Time Limit: 2000/1000 MS ... -
HDU 1392 Surround the Trees .
2011-07-31 20:19 758Surround the Trees Time Limit: ... -
HDU 1234 开门人和关门人 .
2011-07-31 20:17 643开门人和关门人 Time Limit: 2000/1000 ...
相关推荐
hdu5102的ac源码。算法:队列、数据结构、图论、模拟。题意:输入一棵树,输出前k小的点对最短距离dis(i,j)的和。
解题报告|ACM|程序设计参考程序以及题目的分析
杭电OJ部分答案,可以很简单的解决a+b求和问题及其他问题。
HDU的一题........HDU DP动态规
杭电OnlineJudge 200-2099的解题报告
杭电选课插件
一、内容 TT and FF are ... friends. Uh... very very good friends -________-b FF is a bad boy, he is always wooing TT to play the following game with him. This is a very humdrum game....
HDUACM2010版03递推求解.ppt
Hdu 1020解题报告,http://acm.hdu.edu.cn/showproblem.php?pid=1020
ACM HDU 1404 Digital Deletions(博弈).docx
HDU 里面的2000~2099道题目的源码。谢谢支持
杭电 hdu acm 第1084题的解法,ac过了,是一位学长教我的.内有一些中文说明.
ACM HDU题目分类,我自己总结的大概只有十来个吧
2.18.1 HDU4656 卷积取模 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51 2.19 其它公式 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.19.1 Polya . . . ....
杭电acm 一些java语言实现的水题目
本资源为HDU数字图像处理课程 浙江省在线平台的视频课后作业 仅供参考 假设我们有一个mat型的单通道图像,命名为srcMat,我们想得到第i行,第j列的像素值则可以用一下的代码 A. int value= srcMat.at(i)(j)[0]; B...
杭电ACM2000-2099题的解题报告