本题只需要简单地分三种情况讨论即可:
- 输出 $-1$ 的情况,即永远无法到达(只需判断 $a$ 是否小于等于 $b$ 并且一开始的 $8$ 个小时无法爬到 $h_2$ 即可)。
- 输出 $0$ 的情况,即不管你的速度怎么样,只要一开始的 $8$ 个小时能吃到苹果就输出 $0$(只需判断 $h_1$ 加上 $8$ 个小时的路程之和与 $h_2$ 的关系即可)。
- 输出大于 $0$ 的情况,即当上述条件均不满足时,一天一天地模拟直到 $h_1$ 比 $h_2$ 大(用
while
循环模拟简单即可)。
综上,可以直接写出简单的模拟代码(所以这题为什么要评蓝啊?)
$\texttt{AC Code}$:
#include <bits/stdc++.h>
using namespace std;
#define int long long
int h1, h2;
int a, b, ans;
signed main() {
cin >> h1 >> h2;
cin >> a >> b;
if (a <= b && h1 + a * 8 < h2) cout << -1 << endl;
else if (h1 + a * 8 >= h2) cout << 0 << endl;
else {
h1 += a * 8;
while (h1 < h2) {
h1 -= b * 12;
ans++;
h1 += a * 12;
}
cout << ans << endl;
}
return 0;
}