奇思妙想
这道题一看我就有了思路,就是尽量每次都让较小的那个数加上较大的数来更新较小数,这样才能保证每次加之后的结果尽可能的大。尽快达到所要求的值。就先写了以下代码:
#include<iostream>
using namespace std;
int main(){
int a,b,n;
cin>>a>>b>>n;
int step = 0;
while(a<n&&b<n)
{
if(a<b)
{
a+= b;
}
else
{
b+=a;
}
step++;
}
cout<<step<<endl;
return 0;
}
但是有一个测试点始终过不去,又绞尽脑汁想了半天,才发现题目要求是大于,所以写的时候就要是<=
#include<iostream>
using namespace std;
int main(){
int a,b,n;
cin>>a>>b>>n;
int step = 0;
while(a<=n&&b<=n)
{
if(a<b)
{
a+= b;
}
else
{
b+=a;
}
step++;
}
cout<<step<<endl;
return 0;
}
#牛客创作赏金赛#