Ultraviolet A 1347 (POJ 2677) Tour (dual-tuning Euclidean Traveling Salesman Problem)

Source: Internet
Author: User

Ultraviolet A 1347 (POJ 2677) Tour (dual-tuning Euclidean Traveling Salesman Problem)

Description

John Doe, a skilled pilot, enjoys traveling. while on vacation, he rents a small plane and starts visiting beautiful places. to save money, John must determine the shortest closed tour that connects his destinations. each destination is represented by a point in the plane pi = <xi, yi>. john uses the following strategy: he starts from the leftmost point, then he goes strictly left to right to the rightmost point, and then he goes strictly right back to the starting point. it is known that the points have distinct x-coordinates.
Write a program that, given a set of n points in the plane, computes the shortest closed tour that connects the points according to John's strategy.

Input

The program input is from a text file. each data set in the file stands for a participant set of points. for each set of points the data set contains the number of points, and the point coordinates in ascending order of the x coordinate. white spaces can occur freely in input. the input data are correct.

Output

For each set of data, your program shocould print the result to the standard output from the beginning of a line. the tour length, a floating-point number with two fractional digits, represents the result. an input/output sample is in the table below. here there are two data sets. the first one contains 3 points specified by their x and y coordinates. the second point, for example, has the x coordinate 2, and the y coordinate 3. the result for each data set is the tour length, (6.47 for the first data set in the given example ).

Sample Input

31 12 33 141 12 33 14 2

Sample Output

6.477.89


It's a classic problem. The coordinates of n points on the given plane (in ascending order of x ),
Your task is to design a route from the leftmost to the rightmost and then return to the leftmost, exactly once every point. Minimum cost. It can be seen that two people start from the leftmost end at the same time. The minimum cost of one person passing through each vertex.

# Include
     
      
# Include
      
       
# Include
       
        
# Include
        
         
# Include
         
          
Typedef long LL; using namespace std; const int maxn = 110; double x [maxn], y [maxn]; double dp [maxn] [maxn]; double dis (int I, int j) {return sqrt (x [I]-x [j]) * (x [I]-x [j]) + (y [I]-y [j]) * (y [I]-y [j]);} int main () {int n; while (~ Scanf ("% d", & n) {for (int I = 0; I
          
           



Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.