题意:
一个蜗牛在一个6英尺的井中,在日出的时候可以向上爬3英尺,但是在晚会下降1英尺。蜗牛有10%疲劳的因素,这意味着在每个连续天蜗牛上爬比前一天少0.1 * 3 = 0.3英尺,在第几天蜗牛可以离开井?
谨记:
蜗牛每天的爬行距离必须要大于等于0;如果小于的话就要赋值为0;
#include<stdio.h>
#include<iostream>
using namespace std;
int main(){
int h,u,d,f;
double he,up,down,fl;
while(scanf("%d%d%d%d",&h,&u,&d,&f))
{
if(h == 0 && u == 0)
break;
up = u;
down = d;
int day = 0;
fl = 1.0*f/100*up;
he = 0;
while(he >= 0 && he <= h)
{
day ++ ;
he += up;
if(he > h)
break;
he -= down ;
up -= fl;
if(up < 0)
up = 0;
}
if(he > h)
printf("success on day %d\n",day);
else
printf("failure on day %d\n",day);
}
return 0;
}