【杭电】[1302]The Snail

这里写图片描述

蜗牛爬井问题
不同的这次加入了疲劳度
每一天的上升距离要下降
u-=f
(注意不是以当前的距离下降f%,而是以初始的f%)

模拟这一过程
在其中加入越界判断就好

#include<stdio.h>
int main() {
    double h;
    while(scanf("%lf",&h),h) {
        double u,d,f;
        scanf("%lf %lf %lf",&u,&d,&f);
        int cnt=1;
        double t=0;
        f=f/100.0*u;
        while(1) {
            t+=u;
            if(t>h)
                break;
            t-=d;
            if(t<0)
                break;
            u-=f;
            cnt++;
        }
        if(t<0)
            printf("failure on day %d
",cnt);
        else
            printf("success on day %d
",cnt);
    }
    return 0;
}

题目地址:【杭电】[1302]The Snail

原文地址:https://www.cnblogs.com/BoilTask/p/12569534.html