Saturday, August 30, 2014

uva : 573 - The Snail


#include <iostream>
using namespace std;
int main()
{
        double h,u,d,f;
        while (cin>>h>>u>>d>>f)
        {
                if (h==0) break;
                int day=0;
                double fatigue=u*f/100.0,height=0;
                while (height<h && height>=0)
                {
                        double climbed=u-fatigue*day;
                        if (fatigue<=climbed) height+=climbed;
                        day++;
                        if (height>h) break;
                        height-=d;
//                      cout<<"height = "<<height<<endl;
                }
                if (height>=h) cout<<"success on day "<<day<<endl;
                else if (height<0) cout<<"failure on day "<<day<<endl;
        }
return 0;
}

No comments:

Post a Comment