2009年2月12日 星期四

Q573: The Snail

/*
注意:蝸牛不會爬負的,只有晚上會滑下去一個高度
Run time: 0.000
*/
#include <stdio.h>

int main()
{
double H, init, down, factor;
double slide;
double sum;
double last;
int day;
while (scanf("%lf%lf%lf%lf", &H, &init, &down, &factor))
{
if (!H) break;

day = 1;
sum = init;
slide = init*(factor/100);
last = init;

while (true)
{
// morning
if (sum > H)
{
printf("success on day %d\n", day);
break;
}

// night
sum -= down;
if (sum < 0)
{
printf("failure on day %d\n", day);
break;
}

day++;
sum += last-slide;
if (slide != init)
last = last-slide;
}
}
return 0;
}

沒有留言: