zoukankan      html  css  js  c++  java
  • Uva 573 The Snail

    The Snail

    A snail is at the bottom of a 6-foot well and wants to climb to the top. The snail can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. The snail has a fatigue factor of 10%, which means that on each successive day the snail climbs 10% $\times$ 3 = 0.3 feet less than it did the previous day. (The distance lost to fatigue is always 10% of the first day's climbing distance.) On what day does the snail leave the well, i.e., what is the first day during which the snail's height exceeds 6 feet? (A day consists of a period of sunlight followed by a period of darkness.) As you can see from the following table, the snail leaves the well during the third day.

    Day Initial Height Distance Climbed Height After Climbing Height After Sliding
    1 0' 3' 3' 2'
    2 2' 2.7' 4.7' 3.7'
    3 3.7' 2.4' 6.1' -

    Your job is to solve this problem in general. Depending on the parameters of the problem, the snail will eventually either leave the well or slide back to the bottom of the well. (In other words, the snail's height will exceed the height of the well or become negative.) You must find out which happens first and on what day.

    Input

    The input file contains one or more test cases, each on a line by itself. Each line contains four integersH, U, D, and F, separated by a single space. If H = 0 it signals the end of the input; otherwise, all four numbers will be between 1 and 100, inclusive. H is the height of the well in feet, U is the distance in feet that the snail can climb during the day, D is the distance in feet that the snail slides down during the night, and F is the fatigue factor expressed as a percentage. The snail never climbs a negative distance. 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.

    Output

    For each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid back to the bottom) and on what day. Format the output exactly as shown in the example.

    Sample Input

    6 3 1 10
    10 2 1 50
    50 5 3 14
    50 6 4 1
    50 6 3 1
    1 1 1 1
    0 0 0 0
    

    Sample Output

    success on day 3
    failure on day 4
    failure on day 7
    failure on day 68
    success on day 20
    failure on day 2
    

    Miguel A. Revilla 1998-03-10
     
    #include<stdio.h>
    #include<string.h>
    
    int is_end(double h, double& dis, double n)
    {
        if(dis > h) return 1;
        else
        {
            dis -= n;
            if(dis < 0) return -1;
        }
        return 0;
    }
    
    int main()
    {
        int i, j, flag, cnt;
        double h, d, n, f, dis, e;
        while(scanf("%lf%lf%lf%lf", &h, &d, &n, &f) != EOF && h)
        {
            e = d*f/100;
            for(flag=0,dis=cnt=0; !flag; cnt++)
            {
                if(d-e*cnt >= 0) dis += (d - e*cnt);
                flag = is_end(h, dis, n);
            }
            if(flag == 1) printf("success on day %d\n", cnt);
            else if(flag == -1) printf("failure on day %d\n", cnt);
        }
        return 0;
    }


    解题思路:

    模拟题,题目的意思题目已经阐述得很清晰,主要讲一只蜗牛爬墙有升有降的问题,结束的情况为:蜗牛因为降的原因最终还是停留在墙角,或者爬到了最顶端,因为爬会产生劳累从而使一天的形成有所降低(这时要注意行程减少到零不会动的情况,而降的情况是特定的)1y

  • 相关阅读:
    tomcat日志切割脚本
    开源项目推荐:GSL科学计算函数库(GNU Scientific Library),实现VS2019源码编译
    MCUXpresso环境开发(本文争取做到您能够快速简易应用入门,知道大体流程,复杂功能和窗口设置一律不管)
    Arduino uno r3 使用 ESP8266 UARTWiFi 透传模块
    ESP8266引脚的说明
    windows10安装Trading View出错解决办法
    windows or linux 64位安装talib包
    python中list数组指定类型
    面试官问我JVM调优,我忍不住了!
    稳了!我准备了1个晚上的CMS垃圾收集器
  • 原文地址:https://www.cnblogs.com/liaoguifa/p/2941254.html
Copyright © 2011-2022 走看看