A-the Snail

Source: Internet
Author: User

Description

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 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.

Input

The input file contains one or more test cases. 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.

Output

For each test case, output a line indicating whether the snail succeeded (left the well) or failed (slid back to the Botto m) and on the What day. 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

Test instructions: There is a snail at the bottom of the well, ask you if he can leave the wells. Basic questions
H: Height of the well
U: Height per day of climbing
D: The height of the slide every night
F: Snail's fatigue period, less climbing u*f/100 per day

Attention:
1, the snail every day to climb the distance is less than before
2, the snail every day to climb the distance is always greater than 0
3, the function type is best with double
4, when the total distance of the snail crawl is greater than the height of the well when the success, when the snail fell after the height of less than 0 failure

Experience: feel that some of the use of the For loop and break some vague, well, there is a harvest
AC Code:

#include <iostream>
#include <cstdio>
using namespace Std;
int main ()
{
Double a,b,c,d;
Double sum,s;
int i;
while (scanf ("%lf%lf%lf%lf", &a,&b,&c,&d), a)
{
S=b;
i=0;
sum=0;
if (a==0) break;
while (1)
{
i++;
if (s>0) sum=sum+s;
if (sum>a) break;
Sum=sum-c;
if (sum<0) break;
s=s-(d/100) *b;
}
if (sum>a) printf ("Success on Day%d\n", i);
else printf ("Failure on day%d\n", i);

}
return 0;
}







A-the Snail

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.