题意:一只蚂蚁在一个深度为n的洞穴了,现知蚂蚁每分钟可以向上爬u,但爪巴了一分钟后就的休息一分钟,在这一分钟内它会向下滑落d,问要多久蚂蚁可以爬出洞穴
经典小学(雾)数学题,模拟一下就完事
AC代码:
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
int main() {
int n, u, d;
while (scanf("%d %d %d", &n, &u,&d) != EOF) {
if (u ==0&& d==0&& n == 0) {
break;
}
int time = 0;
int now = 0;
while (now<n) {
time++;
now += u;
if (now >= n) break;
time++;
now -= d;
}
printf("%d\n", time);
}
}
本文探讨了一只蚂蚁从深度为n的洞穴中逃出的数学问题,通过模拟蚂蚁每分钟向上爬升u单位,然后休息一分钟下滑d单位的过程,计算蚂蚁完全爬出洞穴所需的总时间。该问题为经典的小学数学题,通过简单的循环结构实现算法求解。


被折叠的 条评论
为什么被折叠?



