whileTrue: H, U, D, F = map(int, input().split()) if H == 0and U == 0and D == 0and F == 0: break f = U * F / 100# fatigue factor ans, cur = 0, 0# day, current height while cur >= 0and cur <= H: ans += 1 cur += U U = max(0, U - f) # 上升高度衰減,但不會衰減到負值 if cur > H: # 爬出井口 flag = True break cur -= D # 掉落高度 if cur < 0: flag = False break print("success"if flag else"failure", "on day", ans)
intmain(){ ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); int H, U, D, F; while (cin >> H >> U >> D >> F && (H || U || D || F)) { double cur = 0, up = U, f = U * F / 100.0; // current height, increase height, fatigue factor int ans = 0; // day bool flag = false; while (cur >= 0 && !flag) { ans += 1; cur += up; up = max(0.0, up - f); // 上升高度衰減,但不會衰減到負值 if (cur > H) flag = true; // 爬出井口 cur -= D; // 掉落高度 } cout << (flag ? "success" : "failure") << " on day " << ans << endl; } return0; }
寫在最後
Cover photo is remixed from @悲鳴樂章, thanks for their work!