FAKETSP - Traveling Salesman

no tags 

According to Wikipedia, "The Traveling Salesman Problem (TSP) is a problem in combinatorial optimization studied in operations research and theoretical computer science. Given a list of cities and their pairwise distances, the task is to find a shortest possible tour that visits each city exactly once. The problem was first formulated as a mathematical problem in 1930 and is one of the most intensively studied problems in optimization. It is used as a benchmark for many optimization methods. Even though the problem is computationally difficult, a large number of heuristics and exact methods are known, so that some instances with tens of thousands of cities can be solved."

Fortunately, you won't have to solve TSP. You're working for a very clever traveling salesman who has already figured out the path he is going to take. All he needs from you is a quick way to figure out how far he traveled after every segment of his tour.

Input

The salesman kept detailed records of his travels. You'll be getting a series of lines of the form "Some text (X, Y)." indicating that the salesman has been at the point X kilometers east and Y kilometers north of the origin of a Cartesian plane.

Output

For each segment of the trip, output the total distance traveled up to that point as a line in the format "The salesman has traveled a total of D kilometers." Show three digits after the decimal point when printing D. Note that the salesman only travels in straight lines (even after a couple of drinks).

Example

Input:
I started out at (0, 5).
Then I traveled to (3.7, 5).
After a couple of drinks I wobbled to (2.7, 4).
The next morning I woke up near (4, 3).
I finished my journey in (-.2, 8).

Output:
The salesman has traveled a total of 3.700 kilometers.
The salesman has traveled a total of 5.114 kilometers.
The salesman has traveled a total of 6.754 kilometers.
The salesman has traveled a total of 13.284 kilometers.

hide comments
Pathan Salman Khan: 2012-02-25 08:03:08

Can the string consist of ( or )?

:D: 2010-12-28 09:21:36

1. YES
2. YES

A. Muh. Primabudi: 2010-12-26 16:39:05

1. -.2 = -0.2?
2. is y can be negative too?

:D: 2010-12-11 10:50:21

on EOF (end of file)

cegprakash: 2010-12-11 09:14:57

how to terminate the input?

~neo~: 2010-10-28 12:39:20

how we terminate input.??

kaushik.mv: 2010-05-14 05:41:53

got AC after changing double to long double.

Last edit: 2010-05-17 12:08:47
Nikhil Garg: 2009-12-23 20:12:57

hint : though , final answer required is 3 digits of precision , read doubles instead of floats.


Added by:Miorel Palii
Date:2009-10-15
Time limit:1s
Source limit:4096B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 C++ 4.3.2 ERL NODEJS OBJC PERL6 SQLITE VB.NET
Resource:University of Florida Team Practice 2009