So, I'm not sure how to properly explain this one, so if something is unclear ask in the comments, I'll try to use the exam question layout so you can easily spot restrictions.
Problem:
You're given an input of Panel
(with fixed size), an array of PointF[]
of fixed size n
, and the distance data that contains distances between each pair of points in indexed arrays of size n
which are accessed via DistanceData
field in the following way:
DistanceData[i].getDistances(k)
returns int
which represents the distance between i-th and k-th point. As a corollary, the DistanceData[k].getDistances(i)
returns the same value. If i==k
, it returns 0
.
Your task is to update the Panel
so that it honestly represents the DistanceData
i.e. if DistanceData[1].getDistances(3) < DistanceData[1].getDistances(4)
then the panel should display 1st and 3rd point closer than the 1st and 4th point etc.
Note: The distance data is inputted independently of the Points previously drawn on the Panel. Or rather, the Panel only contains the number of Points and you need to distribute them according to the values found in DistanceData
.
Note#2: The tag "travelling-salesman" is there to remind you that all the points are dependent on each other i.e. all pairs have unique distance.
My take: The problem I'm facing is if I iteratively solve this - point by point, I find that I break the solution I did in the previous steps. To illustrate this: If I run a loop for 4 points and in the first iteration I draw the points based on the distances from the first point, the next step will almost certainly scrap that solution if it looks at the distances from the second point and so on...