You are on page 1of 4

TopCoder

http://community.topcoder.com/longcontest/?module=ViewProblemSt...

Problem Statement

Contest: Marathon Match 74


Problem: AntiTravelingSalesperson Problem Statement

Normal view

Warning: This problem statement contains subscripts and superscripts that may not display properly if viewed from outside the arena or TopCoder web site. The Traveling Salesperson Problem (TSP) is an old and well-known problem (http://en.wikipedia.org /Traveling_salesman_problem). Here we will call the places to visit "locations" rather than "cities." We consider the two-dimensional Euclidean version of the TSP, where you are given the coordinates of each location and the traveling cost between locations is defined to be the two-dimensional Euclidean distance between the two locations, ( (x -x ) +
1 2 2 2 1/2

(y -y ) )
1 2

The nearest-neighbor heuristic (NN) is a simple technique for finding an approximate solution to the TSP. Given a starting location, the NN-traveler always visits the nearest unvisited location next. Pseudocode for NN is shown below:

currentLocation = initialLocation visited[currentLocation] = true tourLength = 0 while ( count(unvisited) > 0 ) { nextLocation = unvisitedNearestTo(currentLocation) tourLength += distance(currentLocation, nextLocation) currentLocation = nextLocation visited[currentLocation] = true } tourLength += distance(currentLocation, initialLocation)

In this problem, your goal is to select a set of locations (in a square) such that the tour produced by NN is as long as possible. You must start your NN tour at a given initial location and your NN tour must visit some other fixed locations and some additional locations. The initial location and the other fixed locations will be passed to your method in the int[]s X and Y. The initial location will be encoded as (X[0], Y[0]). The other fixed locations will be encoded in (X[i], Y[i]) for i >= 1. The int N will contain the number of additional locations you will place. If N is the number of elements in X (or Y), then N
f f

+ N is the total number locations that will be in the NN tour (one fixed initial location, N - 1 other fixed locations and N
f

additional locations that you will return). Your method, placeLocations, given the parameters described above (N, X, Y), should return a value of int[] which contains the coordinates of your N additional locations. Your return must contain N*2 elements and each element will be an int between 0 and 1,000,000,000, inclusive. The element values in your return will be ordered (x , y , x , y , x ,
0 0 1 1 N-1

N-1

).

Your raw score for each test case will be the length of the NN tour divided by 1,000,000,000. If your return does not contain N*2 elements or if any of the elements is not between 0 and 1,000,000,000, inclusive, then your raw (and final) score for that test case will be zero. Your final score for each provisional and final test case will be (your/best) , where your is your raw score for this test case, best is the highest raw score of all competitors for this test case and the ratio is raised to the fourth power.
4

Definition

1 of 4

25/10/2011 09:03 AM

TopCoder

http://community.topcoder.com/longcontest/?module=ViewProblemSt...

Class: Method: Parameters: Returns:

AntiTravelingSalesperson placeLocations int, int[], int[] int[]

Method signature: int[] placeLocations(int N, int[] X, int[] Y) (be sure your method is public)

Notes
- The time limit is 10 seconds per test case. - The memory limit is 1024 megabytes. - The source code size limit is 65536 bytes. - There are 100 provisional test cases. - A visulalizer/off-line tester is provided. - Although the initial location (X[0], Y[0]) must be the first location in the NN tour, the other fixed locations and the additional locations that you return can be visited in any order. - NN Tie Breaker: If there is more than one nearest unvisited location at some step then the earlist (lowest index) candidate in your return is chosen to be visited. If none of your returned locations is a candidate, then the lowest indexed candidate of the fixed points is chosen. The order of the locations in your return is only significant when a tie exists.

Constraints
- N will be between 10 and 10,000, inclusive. - N will be chosen by N = round(10x), where x is a random floating point number (chosen from a uniform distibution) between 1.0 and 4.0, inclusive (except that the first four examples, with seeds 1, 2, 3 and 4, are hardwired to give N = 10, 100, 1000 and 10000). - X and Y will contain between 3 and min(10,N/3) elements, inclusive. - The number of elements in X and Y will be chosen randomly from a uniform distribution. - X and Y will contain the same number of elements. - Each element of X and Y and will be between 0 and 1,000,000,000 inclusive. - Each element of X and Y will be chosen randomly from a uniform distribution.

Examples
0) N = 10 point 0 = (854833494, 716213306) point 1 = (277032011, 807202676) point 2 = (430818430, 844549427)

1) N = 100 point 0 = (87233015, 187640191) point 1 = (733134899, 885494843) point 2 = (238743005, 755723728)

2)

2 of 4

25/10/2011 09:03 AM

TopCoder

http://community.topcoder.com/longcontest/?module=ViewProblemSt...

N = 1000 point 0 = (750283517, 178242579) point 1 = (313265053, 786252401) point 2 = (786588581, 650518220)

3) N = 10000 point 0 = point 1 = point 2 = point 3 =

(612302661, (381751710, (344074056, (148029080,

257655917) 429791965) 795050248) 545033106)

4) N = 200 point 0 = (711727651, 215075349) point 1 = (459457681, 699422879) point 2 = (965822539, 967261696)

5) N = 8931 point 0 = point 1 = point 2 = point 3 = point 4 = point 5 = point 6 =

(128782045, 716595407) (452512485, 970382194) (715635511, 393473916) (859941041, 956096100) (409217697, 86896632) (23117212, 254435645) (344630154, 546324593)

6) N = 123 point 0 point 1 point 2 point 3 point 4

= = = = =

(29327845, 192575209) (802625069, 460822279) (259910575, 527467580) (926788889, 45838702) (333728888, 18651975)

7) N = 170 point 0 point 1 point 2 point 3 point 4 point 5 point 6

= = = = = = =

(682917127, 447661903) (117503582, 377768314) (50680117, 641869) (516808123, 127944713) (921458613, 887714611) (883919556, 2296448) (94543644, 167142444)

8)

3 of 4

25/10/2011 09:03 AM

TopCoder

http://community.topcoder.com/longcontest/?module=ViewProblemSt...

N = 1070 point 0 = point 1 = point 2 = point 3 = point 4 = point 5 = point 6 = point 7 = point 8 =

(626905271, (414050868, (634924536, (266025891, (213107441, (221800893, (571361335, (366277786, (510965748,

908880520) 522049239) 215791625) 247006561) 875959733) 559667121) 84624842) 348345757) 682484909)

9) N = 66 point 0 = (771179920, 831483078) point 1 = (405668628, 801499559) point 2 = (263568982, 114740778)

This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2006, TopCoder, Inc. All rights reserved.

4 of 4

25/10/2011 09:03 AM

You might also like