Yt14-hdu-the snail Climb well

Source: Internet
Author: User

Problem Descriptiona 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 was up and slides down 1 foot in night while sleeping. The snail has a fatigue factor of 10%, which means this on each successive day the snail climbs 10% * 3 = 0.3 feet less th An it does the previous day. (The distance lost to fatigue are always 10% of the first day ' s climbing distance.) On which day does the snail leave the well, i.e., what's 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 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 would eventually either leave the well or slide back to the bottom of The well. (In other words, the snail ' s height would exceed the height of the well or become negative.) You must find off which happens first and on what day.
Inputthe input file contains one or more test cases, each on a line by itself. Each line contains four integers H, U, D, and F, separated to a single space. If H = 0 It signals the end of the input; Otherwise, all four numbers'll be between 1 and inclusive. H is the height of the feet, you are the distance in feet, the snail can climb during the day, and D is the distance In feet so the snail slides down during the night, and F are 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,. Regardless of the snail climbed, it always slides D feet at night.
Outputfor each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid Bottom) and on. Format the output exactly as shown in the example.
Sample Input
6 3 1 1010 2 1 5050 5 3 1450 6 4 150 6 3 11 1 1 10 0 0 0
Sample Output
Success on day 3failure in day 4failure on day 7failure on day 68success on day 20failure on day 2

Brief explanation:

H-Total high;

U-Initial speed;

D-Glide distance;

Probability of f-speed slipping

The speed at which the down-speed drops.

The code is as follows:

#include <iostream> #include <cstdio>using namespace Std;int main () {    double h,u,d,f,sum,down;    int Day,flag;    while (cin>>h>>u>>d>>f&&h!=0)    {        if (h==0 && u==0 && d==0 && f==0) break        ;    sum=0;    day=0;    flag=1;    Down = (u*f)/100;    while (sum <= H)        {            if (sum < 0)            {                flag = 0;                break;            }            day++;            sum + = U;            if (Sum > H) break            ;        Sum-= D;        U-= down;        }        if (flag)        cout<< "success on Day" <<day<<endl;    else    cout<< "failure on Day" <<day<<endl;    }    return 0;}

Operation Result:



Do English topic really suffer, Baidu Youdao translation results I am also drunk,,, heart plug.

Yt14-hdu-the snail Climb well

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.