The Snail
Time limit:3000ms Memory limit:0kb 64bit IO format:%lld &%llu
Submit Status Practice UVA 573
Appoint Description:
Description
Download as PDF
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, in each successive day the snail climbs 10% x 3 = 0.3 feet Less than 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 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
Snail in a well, day climb, Night will fall, at the same time because of fatigue, each day can climb the height of the decrease, ask you if he can come out, if possible, out of the day, or failure of the day direct simulation can be#include <iostream>#include <algorithm>#include <map>#include <cstdio>#include <cstdlib>#include <vector>#include <cmath>#include <cstring>#include <string>using namespace STD;Const intmaxn= -;typedef Long LongLL;intA[MAXN];intMain () {#ifndef Online_judge //freopen ("Text//in.txt", "R", stdin); #endif //Online_judge DoubleH,u,d,f; while(scanf("%LF%LF%LF%LF", &h,&u,&d,&f) && (h| | u| | d| | f)) {Doubles=0;intcn1=0; f=u*f/100.0;intT while(true){if(u>=0) S+=u; ans++;if(S>H) {printf("Success on day%d\n", ans); Break; } S-=d;if(s<0){printf("Failure on day%d\n", ans); Break; } u-=f; } }return 0;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
uva573 the Snail