注解
1、模拟题。可以模拟蚂蚁整个向上爬的过程。
2、也可以用来找规律。除了向上爬的最后一步,其他步相当于每2分钟向上(u-d),而最后一步最多可以爬u,所以剩下的高度最大为(n-u)。所以ceil((n-u)/(u-d))*2就是前面的时间,再加上最后一次向上爬u,不需要下滑。
3、注意精度,何时用double,何时用int。为了方便,n、u、d统一采用double类型,而输出的时间按题目要求,必须为int类型。
代码
#include <iostream>
#include <cmath>
using namespace std;
int main() {
double n, u, d;
scanf("%lf %lf %lf", &n, &u, &d);
while(n || u || d){
int ans = ceil((n-u)/(u-d));
ans = ans*2+1;
printf("%d\n", ans);
scanf("%lf %lf %lf", &n, &u, &d);
}
return 0;
}