UVa 573 - The Snail

Problem Link: https://uva.onlinejudge.org/external/5/573.pdf



*********************** Solution ***********************

#include<bits/stdc++.h>
using namespace std;

#define sf scanf
#define pf printf
#define psb push_back
#define fast ios_base::sync_with_stdio(false)

typedef map<string, int>mpsi;
typedef map<int, string>mpis;
typedef long long LL;

const int high = 2e5+10;

int main()
{
    fast;
    double H, U, D, F;
    while(cin >> H && H)
    {
        cin >> U >> D >> F;
        bool fail = false;
        int day = 0;
        F = (F * U) * 0.01;

        //cout << "F = " << F << "\n";

        double cnt = 0.0;
        double tmp = U;

        while(true)
        {
            day += 1;
            cnt = tmp > 0.0 ? cnt + tmp : cnt;

            //cout << "1. cnt = " << cnt << " day = " << day << "\n";

            if(cnt > H)
            {
                fail = false;
                break;
            }

            cnt -= D;

            //cout << "2. cnt = " << cnt << "\n";

            if(cnt < 0.0)
            {
                fail = true;
                break;
            }

            tmp -= F;

        }

        if(fail)
        {
            cout << "failure on day " << day << "\n";
        }

        else
        {
            cout << "success on day " << day << "\n";
        }

    }

    return 0;
}

Comments

Popular posts from this blog

SPOJ-CMG - Collecting Mango

LightOJ 1009 - Back to Underworld

LeetCode Palindrome Number