0% found this document useful (0 votes)
176 views6 pages

Fishing Problem: 10 August 2016 Advance Problem Arun Mahajan

This document describes a fishing problem to minimize the total walking distance for fishermen. There are multiple fishing spots and gates, with fishermen waiting at each gate to be assigned to the nearest open spot. The problem is to calculate the minimum total distance walked if the gates are opened in different orders, assigning fishermen to spots intelligently based on distance. A solution is proposed to write a function assigning fishermen to spots for each gate, and to generate all combinations of gate openings to find the optimal order.

Uploaded by

Soumalya Bhanja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
176 views6 pages

Fishing Problem: 10 August 2016 Advance Problem Arun Mahajan

This document describes a fishing problem to minimize the total walking distance for fishermen. There are multiple fishing spots and gates, with fishermen waiting at each gate to be assigned to the nearest open spot. The problem is to calculate the minimum total distance walked if the gates are opened in different orders, assigning fishermen to spots intelligently based on distance. A solution is proposed to write a function assigning fishermen to spots for each gate, and to generate all combinations of gate openings to find the optimal order.

Uploaded by

Soumalya Bhanja
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

Fishing Problem

10th August 2016 Advance


Problem

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

After G1 gate is opened, fishermen are placed at following spots.


Distance = 11m
  1 1 1 1 1

G1
After G2 gate is opened, fishermen are placed at
following spots.
Distance
  = 15m 1 1 1 1 2 2

G1 G2

After G3 gate is opened, fishermen are placed at


following spots.
Distance
  =1 3m 1 1 1 1 2 2 3 3

G1 G2
G3

Total distance in this order : 11 + 5 + 3 = 19


If gates are opened in order G2->G1->G3
Case1 –Last fisherman of gate#2 is placed at pos # 7
After G2 gate is opened, fishermen are placed at following spots.
Distance = 3m
  2 2

G2
After G1 gate is opened, fishermen are placed at
following spots.
Distance
1 = 112m 1 1 1 2 2

G1 G2

After G3 gate is opened, fishermen are placed at


following spots.
Distance
1  =1 3m 1 1 1 2 2 3 3

G1 G2
G3

Total distance in this order : 3+12+3 = 18


If gates are opened in order G2->G1->G3
Case2 –Last fisherman of gate#2 is placed at pos # 5
After G2 gate is opened, fishermen are placed at following spots.
Distance = 3m
  2 2

G2
After G1 gate is opened, fishermen are placed at
following spots.
Distance
1 = 114m 1 1 2 2 1

G1 G2

After G3 gate is opened, fishermen are placed at


following spots.
Distance
1  =1 3m 1 1 2 2 1 3 3

G1 G2
G3

Total distance in this order : 3+14+3 = 20


Solutions
– Write function which takes gate # as input and
assigns fishermen to nearest spots for that gate.
It returns minimum distance and total number
of position possible for last fishermen. If number
of positions are 2, returns both positions.
– Generate all combinations and assigns
fishermen in all gate combinations to calculate
minimum walking distance.

– Generating combination can be done in both


recursive and iterative way.

fishery_iterative.c fishery_recursive.c input.txt output.txt

You might also like