UVA 573 The Snail

来源:互联网 发布:淘宝哪家iphone 编辑:程序博客网 时间:2024/06/04 23:40

题目

蜗牛

分析

  1. If the fatigue factor drops the snail’s climbing distance below zero, the snail does not climb at all that day.
  2. In other words, the snail’s height will exceed the height of the well or become negative.

代码

#include <stdio.h>int test(int h, int u, int d, int f, int* day){    *day = 0;    double ks = u, s = 0;    while (++*day) {        s += ks;        if (s > h) return 1;        s -= d;        if (s < 0) return 0;        ks -= f/100.0 * u;        if (ks < 0) ks = 0;    }}int main(void){    int h, u, d, f, day;    while (scanf("%d%d%d%d", &h, &u, &d, &f), h) {        printf(test(h, u, d, f, &day)? "success": "failure");        printf(" on day %d\n", day);    }    return 0;}
0 0