Description
有一口深度为high米的水井,井底有一只青蛙,它每天白天能够沿井壁向上爬up米,夜里则顺井壁向下滑down米,若青蛙从某个早晨开始向外爬,对于任意指定的high、up和down值(均为自然数),计算青蛙多少天能够爬出井口?
Input
输入3个正整数:high、up和down。
Output
输出一个整数,表示天数。输出单独占一行。
Sample Input
10 2 1
Sample Output
9
HINT
循环模拟。注意,不能简单地认为每天上升的高度等于白天向上爬的距离减去夜间下滑的距离,因为若白天能爬出井口,则不必等到晚上。
题意概括:此题是一道循环模拟题。因为白天上升,晚上下降,所以一定是白天爬出井外。
解题思路:
1: 用一个for循环来模拟这个过程即可
错误原因:
1:如果是output limit exceed,可以尝试去除多实例。
经验总结:无
我的AC代码:
#include<stdio.h>
int main(void)
{
int high, up, down, i, t =0;
scanf("%d%d%d", &high, &up, &down);
for(i = 1; ; i ++)
{
t += up;
if(t >= high)
{
break;
}
t -= down;
}
printf("%d\n", i);
return 0;
}
{
int high, up, down, i, t =0;
scanf("%d%d%d", &high, &up, &down);
for(i = 1; ; i ++)
{
t += up;
if(t >= high)
{
break;
}
t -= down;
}
printf("%d\n", i);
return 0;
}