The snail iltime limit: 2000/1000 MS (Java/others) memory limit: 65536/32768 K (Java/Others)
Total submission (s): 1461 accepted submission (s): 1069
Problem descriptiona snil 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 the first day's Climbing distance.) on what day does the snail il leave the well, I. e., what is the first day during which the snail Il'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 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.
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 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 Il can climb during the day, D is the distance in feet that the snail il slides down during the night, and f is the fatigue factor expressed as a percentage. the snail il 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 snil climbed, it always slides D feet at night.
Outputfor each test case, output a line indicating whether the snil 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 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
Sourcemid-Central USA 1997
Question trap: fatigue is the percentage calculated based on the first day, and the rising height every day. It must be a double type and cannot be changed to int. Int is changed to WA. The Code is as follows:
# Include <stdio. h> int main () {int H, D, F, I; double U; while (~ Scanf ("% d", & H), h) {scanf ("% lf % d", & U, & D, & F); double sum = 0, p, u = u * (1.0 * f/100); for (I = 0; I ++) {sum + = u-d; // Add the daily net height if (sum> = h) {p = 1; break;} else if (sum <0) {P = 0; break ;} u-= u;} p? Printf ("success on day % d \ n", I): printf ("Failure on day % d \ n", I + 1 ); // here, I + 1 is calculated based on the daily net height. It does not slide down during the day, so another one is added. } Return 0 ;}
HDU 1302 (the snail il)