avatar
P*b
1
Fibonacci Numbers: A number is said to be Fibonacci number if it follows the
fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not nec
essarily start with 1, as with the normal fibonacci series. So, in this new
definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and
so is 252550(25,25,50).
So, given any two numbers as input, print out all the Fibonacci Numbers with
in that range..
avatar
c*e
2

the
nec
new
and
with
Which range?

【在 P*******b 的大作中提到】
: Fibonacci Numbers: A number is said to be Fibonacci number if it follows the
: fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not nec
: essarily start with 1, as with the normal fibonacci series. So, in this new
: definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and
: so is 252550(25,25,50).
: So, given any two numbers as input, print out all the Fibonacci Numbers with
: in that range..

avatar
s*t
3
given (a,b)
for(i=1; ; i++){
//if "ii(i+i)" is larger than b, break
//else, find all fib numbers start with i, till it's larger than b, put
those larger than a into a set
}

the
nec
new
and
with

【在 P*******b 的大作中提到】
: Fibonacci Numbers: A number is said to be Fibonacci number if it follows the
: fibonacci property. (Ex: 112, 1123, etc). But additionally, it need not nec
: essarily start with 1, as with the normal fibonacci series. So, in this new
: definition, 112(1,1,2) is a fibonacci number and so is 121224(12,12,24), and
: so is 252550(25,25,50).
: So, given any two numbers as input, print out all the Fibonacci Numbers with
: in that range..

avatar
P*b
4
thanks

put

【在 s*********t 的大作中提到】
: given (a,b)
: for(i=1; ; i++){
: //if "ii(i+i)" is larger than b, break
: //else, find all fib numbers start with i, till it's larger than b, put
: those larger than a into a set
: }
:
: the
: nec
: new

avatar
I*A
5
能不能详细说说?

【在 P*******b 的大作中提到】
: thanks
:
: put

avatar
s*t
6
我随便写了一个,凑合看下吧。。
std::set fibRange(int m, int n)
{
assert(m<=n);
std::set Set;
std::stringstream ss;
std::string s;
int n1,n2, tmp;
for(int i=1; ; i++){
n1 = i;
n2 = i+i;
ss.str("");
ss<s = ss.str();
if(atoi(s.c_str()) > n){
break;
}
while( atoi(s.c_str()) < m){
tmp = n1 + n2;
n1 = n2;
n2 = tmp;
ss<s = ss.str();

【在 I**A 的大作中提到】
: 能不能详细说说?
avatar
I*A
7
没有特别看明白
你看我理解的对不对啊?
就是说
对每一个i, we will check whether ii(i+i)是不是在range内,在的话就放进去
然后看ii(i+i)(i+i+i)在不在range内,在的话就放进去,直到>range为止,再检查下
一个i。。。
这个题目所谓的fibnumber 必须是start with two same numbers?
ij(i+j)算不算?

【在 s*********t 的大作中提到】
: 我随便写了一个,凑合看下吧。。
: std::set fibRange(int m, int n)
: {
: assert(m<=n);
: std::set Set;
: std::stringstream ss;
: std::string s;
: int n1,n2, tmp;
: for(int i=1; ; i++){
: n1 = i;

avatar
s*t
8
那样就无穷无尽了

【在 I**A 的大作中提到】
: 没有特别看明白
: 你看我理解的对不对啊?
: 就是说
: 对每一个i, we will check whether ii(i+i)是不是在range内,在的话就放进去
: 然后看ii(i+i)(i+i+i)在不在range内,在的话就放进去,直到>range为止,再检查下
: 一个i。。。
: 这个题目所谓的fibnumber 必须是start with two same numbers?
: ij(i+j)算不算?

avatar
I*A
9
哈哈哈,也是。。
不会无穷无尽的,有很多倒是真的。。
还有,直觉上觉得,因为有个start value参数
循环的时候,是不是不要从1开始更快些?
对于你的logic,我理解的没错?

【在 s*********t 的大作中提到】
: 那样就无穷无尽了
avatar
s*t
10
没错

【在 I**A 的大作中提到】
: 哈哈哈,也是。。
: 不会无穷无尽的,有很多倒是真的。。
: 还有,直觉上觉得,因为有个start value参数
: 循环的时候,是不是不要从1开始更快些?
: 对于你的logic,我理解的没错?

avatar
I*A
11
thanks
我自己又想了一下
是要从1开始

【在 s*********t 的大作中提到】
: 没错
avatar
c*t
12
while( atoi(s.c_str()) < m){
tmp = n1 + n2;
n1 = n2;
n2 = tmp;
ss<s = ss.str();
}
这段代码看不出来有啥用,是否可以去掉?
while( atoi(s.c_str()) <= n && atoi(s.c_str())>m )
即可.
avatar
s*t
13
如果开头几个数如果小于m则进不去循环了
改的话可以这样:
去掉前面的while(...在while(...if( xxx > m ) xxx.insert(xxx)
即可

【在 c********t 的大作中提到】
: while( atoi(s.c_str()) < m){
: tmp = n1 + n2;
: n1 = n2;
: n2 = tmp;
: ss<: s = ss.str();
: }
: 这段代码看不出来有啥用,是否可以去掉?
: while( atoi(s.c_str()) <= n && atoi(s.c_str())>m )
: 即可.

avatar
x*y
14
what if the # of characters in b > the # of characaters in a? Then, even if
ii(i+i)> the first correponding characters in b, we can not eliminate it...

put

【在 s*********t 的大作中提到】
: given (a,b)
: for(i=1; ; i++){
: //if "ii(i+i)" is larger than b, break
: //else, find all fib numbers start with i, till it's larger than b, put
: those larger than a into a set
: }
:
: the
: nec
: new

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。