Question: C++ Code help Closest Villages Problem Problem : n lg n algorithm to Closest Villages Problem More than 80% of Ethiopian citizens live in rural

C++ Code help

Closest Villages Problem

Problem: nlgn algorithm to Closest Villages Problem

More than 80% of Ethiopian citizens live in rural villages. Very few of the Tigrina villages in northern Ethiopia have electricity or any form of developed travel system connecting them with the rest of the country.

This assignment is the first step in determining a cost-effective manner of connecting all the villages together. This is just the first step because all we are finding are the initial two villages that are the closest to each other, between which the first connecting travel lines will be placed. The Ethiopian government would like us to continue this process, continually finding the next two closest villages and using the minimum spanning tree approach, to build the complete lowest-cost network for connecting all the villages; however, that is beyond the scope of this assignment.

The closest villages can be found in a straightforward manner using the brute-force technique of comparing each village to every other village and determining the closest distance in that way. This technique is a good to confirm the correctness of other approaches, but it does not meet the nlgn performance requirement.

Input

The console input is a listing of village coordinates in a 2D space with the origin at the southwestern most location in Tigray. Your program should read in a list of village coordinates from the console and report the names of the closest pair of villages and the distance between them.

The coordinates for the villages are in the range of 0 ... 1,000,000. The village names are no more than 256 characters and terminate with the end of the line.

To simplify handling input, the first line of the file will contain the total number of villages (< 1,000,000). If the distance between the closest villages is not less than 1,200, greater than the length or breadth of Ethiopia, output Infeasible.

Sample Input

5

10 39 mekelle

15 21 wukro

20 44 adigrat

40 10 axum

56 43 debre_damo

Sample Output

mekelle and adigrat are closest with a distance of 11.18034

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!