Our solution to the Traveling Salesperson 2D problem on Kattis (oldkattis:tsp), as part of the course DD2440 Advanced Algorithms at KTH.
See below for the full problem statement.
Your program should take as input a single TSP instance. It will be run several times, once for every test case. The time limit is per test case.
The first line of standard input contains an integer
The distance between two points is computed as the Euclidean distance between the two points, rounded to the nearest integer.
Standard output should consist of
Let
The score on a test case is
The algorithm giving the value
GreedyTour
tour[0] = 0
used[0] = true
for i = 1 to n-1
best = -1
for j = 0 to n-1
if not used[j] and (best = -1 or dist(tour[i-1],j) < dist(tour[i-1],best))
best = j
tour[i] = best
used[best] = true
return tour
The sample output gives the tour found by GreedyTour
on the sample input. The length of the tour is 323.
Sample Input 1 | Sample Output 1 |
|
|