196k views
4 votes
A pilot was asked to drop food packets in a terrain. He must fly over the entire terrain only once but cover a maximum number of drop points. The points are given as inputs in the form of integer co-ordinates in a twodimensional field. The flight path can be horizontal or vertical, but not a mix of the two or diagonal. Write an algorithm to find the maximum number of drop points that can be covered by flying over the terrain once.

User Lisarae
by
7.6k points

1 Answer

5 votes

Final answer:

Use a greedy algorithm to find the maximum number of drop points that can be covered by flying over the terrain once.

Step-by-step explanation:

To find the maximum number of drop points that can be covered by flying over the terrain once, you can use a greedy algorithm approach. Here's the algorithm:

  1. Sort the drop points based on their x-coordinate in increasing order.
  2. Start from the leftmost drop point and fly to the rightmost drop point, dropping food packets at each point.
  3. For any two adjacent drop points with the same x-coordinate, drop the food packets only at the drop point with the highest y-coordinate.
  4. Return the total number of food packets dropped.

This algorithm ensures that the pilot covers the maximum number of drop points by flying over the terrain once.

User Katrin Leinweber
by
7.4k points