Search Here

Monday, June 8, 2015

UVa - 573 ( The Snail Solution )

Try Yourself First. For help Scroll Down .


Tip : Its an easy problem. Before seeing code just read the problem once. Do the work step by step.  Just keep eye on one point if the " Fatigue Factor ". It won't be negative. It it will negative it won't add with the other legal operation you are doing. You have to omit it.  After doing this problem's code without seeing just check this test case [ 56    3   1   5 ] . It will lead you to the success.

Code

#include<bits/stdc++.h>

using namespace std;

int main()
{
    double H, U, D, F;
    while(scanf("%lf %lf %lf %lf", &H, &U, &D, &F)==4 && H!=0.0)
    {
        double ff = U*(F/100);
        double ih = 0.0;
        int day=0;
        while(1)
        {
            day++;
            if(U>0) ih = ih + U;
            U = U - ff;
            if(ih>H)
                break;
            ih = ih - D;
            if(ih<0)
                break;
        }
        if(ih>=0)
            printf("success on day %d\n",day);
        else
            printf("failure on day %d\n",day);
    }
    return 0;
}


=> Need Help . Leave a comment .

No comments:

Post a Comment