A snail is at the bottom of a 6-foot well and wants to climb to the top. the snail Il can climb 3 feet while the sun is up, but slides down 1 foot at night while sleeping. the snail Il has a fatigue factor of 10%, which means that on each successive day the snail Il
Climbs 10% 3 = 0.3 feet less than it did the previous day. (The distance lost to fatigue is always 10% of
FirstDay's climbing distance.) on what day does the snil leave the well,
I. e., What is the first day during which the snail's heightExceeds6 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 il leaves the well-known 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 Il 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 Integers
H,U,D, AndF, 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.
HIs the height of the well in feet,UIs the distance in feet that the snail Il can climb during the day,
DIs the distance in feet that the snail slides down during the night, and
FIs the fatigue factor expressed as a percentage. The snail IlNeverClimbs a negative distance. If the fatigue factor drops the snail Il's climbing distance below zero, the snail il does not climb at all that day. Regardless of how far the snail Il
Climbed, it always slidesDFeet at night.
Output
For each test case, output a line indicating whether the snail il succeeded (left the well) or failed (slid back to the bottom) and on what day. format the output
ExactlyAs 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 on day 4failure on day 7failure on day 68success on day 20failure on day 2
In the past, the difference was that the distance between the snails climbed down every day will be reduced by percentage. After the distance between the snails climbed up and down is smaller than 0, he only fell down. The days of failure are his original position. The number of successful days is to climb up to a height greater than the given
# Include <stdio. h>
Void main ()
{Double H, U, D, F, H;
Int Day;
While (scanf ("% lf", & H, & U, & D, & F ))
{If (H = 0) break;
Day = 0; F = u x F/100; h = 0;
While (h> 0)
{If (u> 0) H + = u; ++ Day;
If (h> H) break;
H-= D;
If (H <0) break;
U-= F;
}
If (h> = h) printf ("success on day % d \ n", Day );
Else printf ("Failure on day % d \ n", Day );
}
}