-
Notifications
You must be signed in to change notification settings - Fork 2
/
00573.cpp
45 lines (42 loc) · 854 Bytes
/
00573.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
/*
Solution a problem 573 at UVA's online judge
*/
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int H,U,D,F;
while(1)
{
/*
H is the height of the well
U is the distance the snail can climb each day
D is the distance slid during the night
F is the fatigue factor
*/
cin >> H >> U >> D >> F;
if(H == 0)
break;
//Multiply all numbers by 100 so that doubles never have to be used
H*=100; U*=100; D*=100;
//Calculate the base fatigue distance
F = U / 100 * F;
int climbed = 0; //Distance climbed
int day = 0;
while(climbed <= H && climbed >= 0)
{
climbed += max(U - day*F,0);
day++;
if(climbed > H)
break;
climbed -= D;
}
if(climbed > H)
cout << "success on day " << day;
else
cout << "failure on day " << day;
cout << endl;
}
return 0;
}