青蛙爬井 计蒜客 - T1376
问题描述
有一口深度为 high 米的水井,井底有一只青蛙,
它每天白天能够沿井壁向上爬 up 米,夜里则顺井壁向下滑 down 米,
若青蛙从某个早晨开始向外爬,对于任意指定的 high、up 和 down 值(均为自然数),
计算青蛙多少天能够爬出井口?
输入格式
输入 3 个正整数:hight、up 和 down。
输出格式
输出一个整数,表示天数。输出单独占一行。
注意:不能简单地认为每天上升的高度等于白天向上爬的距离减去夜间下滑的距离,因为若白天能爬出井口,则不必等到晚上。
输入样例
10 2 1
输出样例
9
数据范围:1 ≤down < up < high ≤1000 。
- 参考程序
#include<iostream>
using namespace std;
int main(){
int hight, up, down;
cin>>hight>>up>>down;
int ans=0, l=0;
while(l<hight){
ans++;
l += up;
if(l>=hight) break;
l -= down;
}
cout<<ans<<endl;
return 0;
}