Fishing Problem: 10 August 2016 Advance Problem Arun Mahajan
Fishing Problem: 10 August 2016 Advance Problem Arun Mahajan
Arun Mahajan
Problem description
Given:
Fishing Spots: 1 to N
3 Gates with gate position and number of fishermen waiting to get in
Distance between consecutive spots = distance between gate and nearest spot =
1m
Fishermen are waiting at the gates to get in and occupy nearest fishing spot. Only
1 gate can be opened at a time and all fishermen of that gate must occupy spots
before next gate is open.
There could be 2 spots closest to the gate. Assign only 1 spot to the last
fisherman in such a way that we get minimum walking distance. For rest of the
fishermen, ignore and assign any one.
Write a program to return sum of minimum distance need to walk for fishermen.
Distance is calculated as gate to nearest spot + nearest spot to closest vacant
spot.
If the gate is at position 4, then fishermen occupying spot 4 will walk 1 m,
fishermen occupying spot 3 or 5 will walk 2 m (1m for gate to spot#4 + 1M for
1 #4 to2 spot #33 or 5).4 5 6 7 8 9 10
spot
G14,6 and
Ex: 3 gates at position G2 G3 = 10
10. Total fishing spots
(5 Fishermen) (2 Fishermen)
If gates are opened in order G1->G2->G3
G1
After G2 gate is opened, fishermen are placed at
following spots.
Distance
= 15m 1 1 1 1 2 2
G1 G2
G1 G2
G3
G2
After G1 gate is opened, fishermen are placed at
following spots.
Distance
1 = 112m 1 1 1 2 2
G1 G2
G1 G2
G3
G2
After G1 gate is opened, fishermen are placed at
following spots.
Distance
1 = 114m 1 1 2 2 1
G1 G2
G1 G2
G3