UVa:573 - The Snail

需要注意的地方是:

Height After Climbing 大于井的高度时才算成功,Height After Climbing 和 Height After Sliding 小于等于0时才算失败,

而且“If the fatigue factor drops the snail's climbing distance below zero, the snail does not climb at all that day. Regardless of how far the snail climbed, it always slides D feet at night”(见原文),如果 Distance Climbed 小于0时,Height After Climbing 不再等于 Initial Height + Distance Climbed,而直接等于 Initial Height。


#include
int main() {
    int H, U, D, F;
    while (scanf("%d%d%d%d", &H, &U, &D, &F) != EOF) {
        if(!H)
            break;
        float IH = 0, DC = U, HAC = U, HAS = U - D;
        int day = 1;
        while(HAC <= H && HAC >= 0.0 && HAS >= 0.0) {
            day++;
            IH = HAS;
            DC -= U*F/100.0;
            if(DC < 0.0)
                HAC = IH;
            else
                HAC = IH + DC;
            HAS = HAC - D;
        }
        if(HAC > H)
            printf("success on day %d\n", day);
        else if(HAC < 0.0 || HAS < 0.0)
            printf("failure on day %d\n", day);
    }
    return 0;
}

--------------------------------------------------------------------------------------------

            Keep It Simple,Stupid!

--------------------------------------------------------------------------------------------

你可能感兴趣的:(题目分类:数学基础,OJ:UVa)