View the step-by-step solution to:

Content -> Connect-the-dots is a new popular game on iPad. At the onset of the game, n random numbers of dot are placed on the screen. The ith dot...

Content: 正體->简体


Connect-the-dots is a new popular game on iPad. At the onset of the game, n random numbers of dot are placed on the screen. The ith dot has the coordinate of (xi, yi). The player must connect all the dots via straight line-segments so that no dot is isolated. The game is scored as follows:
Sum of integral length of edge(i, j) for all line-segments i-j.
The integral length of edge (i, j) is computed as |yi-yj|+|xi-xj|. Write a program to compute and output the minimum possible score.
Input:


First line contains an integer indicating the number of test cases to follow. For each test case, coordinates of random number of dots are given. The coordinate of “-1 -1” indicates the end of a test case. There are can be at most 5000 dots. The coordinates are all positive integer between 0 and 1000.
Output:


For each test case, output the minimum score possible when all the dots are inter-connected.
Sample Input:

若題目沒有特別說明,則應該以多測資的方式讀取,若不知如何讀取請參考 a001 的範例程式。2
1 1 2 2 3 3 -1 -1
0 1 1 0 1 1 0 0 -1 -1
Sample Output :

4
3

Recently Asked Questions

Why Join Course Hero?

Course Hero has all the homework and study help you need to succeed! We’ve got course-specific notes, study guides, and practice tests along with expert tutors.

-

Educational Resources
  • -

    Study Documents

    Find the best study resources around, tagged to your specific courses. Share your own to gain free Course Hero access.

    Browse Documents
  • -

    Question & Answers

    Get one-on-one homework help from our expert tutors—available online 24/7. Ask your own questions or browse existing Q&A threads. Satisfaction guaranteed!

    Ask a Question