Advertisement
MiinaMagdy

573 - The Snail

Sep 2nd, 2022
863
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.64 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. #define ll long long
  6. #define endl '\n'
  7. #define sz(x) int(x.size())
  8. #define all(x) x.begin(), x.end()
  9.  
  10. int main() {
  11.     ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  12.     double h, u, d, f;
  13.     while (scanf("%lf %lf %lf %lf", &h, &u, &d, &f), h) {
  14.         int day = 1;
  15.         double curr_pos = 0;
  16.         bool can = true;
  17.         f = u * (f / 100);
  18.         for (; day; day++) {
  19.             curr_pos += u;
  20.             if (curr_pos > h) break;
  21.             u = max(double(0), u - f);
  22.             curr_pos -= d;
  23.             if (curr_pos < 0) {
  24.                 can = false;
  25.                 break;
  26.             }
  27.         }
  28.         cout << (can ? "success" : "failure") << " on day " << day << endl;
  29.     }
  30. }
  31.  
Tags: UVA CP3
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement