+ 3

[ASSIGNMENT] Organization of a tourist trip (short description)

A tourist goes from the City to the Mountain (D is a distance between them). For the trip he takes some food (A). While traveling he eats food with speed S. It means that he can pass distance A/S before food will be eaten. So if D > 1/2*A/S he will not be able to reach Mountain at once. That's why he organizes some storages of food on his way. He goes up by some distance, stores some food, goes down, take new food, and go up again... Your task is to minimize the amount of required food for given D, A and S.

10th Apr 2018, 3:02 AM
Nevfy
9 Answers
+ 2
@VcC Sure, that's up to you. But I really recommend to come back in several months and to try it again, because I found such kind of tasks to be very educational (may be not exactly this particular one). I will give you a hint about solution: "dynamic programming".
10th Apr 2018, 8:01 PM
Nevfy
+ 1
@VcC I hope I understood right your question. You can not climb a mountain higher then 1/2*A/S at once, because you need to go up and down while food is not eaten, so you will pass A/S distance in total, when you came back in the city. If you want to go higher, you need to store some food at some hight in advance to be able to restore your amount of food in a next hike For example, D = 3/4*A/S. Then you can to go up by D1 = 1/4*A/S, store there 1/2*A of food and go down. Ai this first hike you spend all food you had: you passed twice (up and down) D1 distance and for that you used 2*D1*S = 1/2*A of food and you stored 1/2*A of food. Then, the next day you leave the city with A amount of food, go up to the storage. When arrived 3/4*A food left, you take out 1/4*A food from the storage, recovering the full amount of food and keeping also 1/4*A for way back. Then you go up by D2 = 1/2*A/S and you reach the top of the mountain, because you passed D1+D2 = 3/4*A/S = D. And you still have 1/2*A food with you to go down till the storage, take out the rest 1/4*A food from there and successfully reach the city. In a such way total amount of food you spent is B = 2*A. Increasing the amount of spent food it is possible to climb on a mountain of any hight. Good luck with the solution!
10th Apr 2018, 2:40 PM
Nevfy
0
If you found this text to be not clear enough or if you want to get some hints about solution, you can look this topic: https://www.sololearn.com/Discuss/1203736/?ref=app And good luck with implementation of it! I will publish one of the possible solutions but not the optimal one in a couple of days. And I will publish optimal solution a bit after.
10th Apr 2018, 3:06 AM
Nevfy
0
If you can you can pass A/S before food is eaten why can you climb a mountain of A/S-epsilon ?
10th Apr 2018, 9:20 AM
VcC
VcC - avatar
0
So your goal is to go up then down again ?
10th Apr 2018, 2:59 PM
VcC
VcC - avatar
0
This is not really a coding exercice - more a logic puzzle.
10th Apr 2018, 3:32 PM
VcC
VcC - avatar
0
@VcC 1. Yes, the goal is to go back and forth. 2. Well, it is both. You need to understand the logic, and then to code it correctly, which also can be tricky. 3. Your code is a good start, it works well with some simple cases, but it requires further improvements to give correct results. See more info in comments to the code.
10th Apr 2018, 6:18 PM
Nevfy
- 1
I dont have enough time and prefer spending time on problems which solution will learn me stg. Sorry pal !
10th Apr 2018, 7:44 PM
VcC
VcC - avatar