eolymp
bolt
Try our new interface for solving problems
Problems

Continuous Drawing

Continuous Drawing

\includegraphics{https://static.e-olymp.com/content/65/65624bcf284d20809ef328f3e2eaca1bbe093ca9.jpg} A simple task!! You will be given the end points of some line segments. Just draw them. Too easy, right??? You decide to challenge yourself and thus plan to add some constraints. \begin{enumerate} \item Start from the end point of any line segment. \item Do not lift your pen off the paper. \item You can go over a line more than once. \item Do not draw any line other than the ones mentioned. \item You can only change direction at integer coordinates of \textbf{x} & \textbf{y}. \item Use the least amount of ink needed. \end{enumerate} You need \textbf{1} unit of ink to draw one unit of line. Distances between successive points are \textbf{1} unit. So Distance (\textbf{A1} to \textbf{B1}) = \textbf{1} unit and Distance (\textbf{A1} to \textbf{A2}) = \textbf{1} unit. \InputFile The first line of input is an integer \textbf{T} (\textbf{T} < \textbf{20}) that indicates the total number of test cases. Each case starts with an integer \textbf{N} (\textbf{N} < \textbf{10}). Then \textbf{N} lines follow, each describing a line segment. A line segment is defined by two points \textbf{Y1X1} and \textbf{Y2X2}. \textbf{Y1} and \textbf{Y2} will be from \[\textbf{A}, \textbf{E}\].And \textbf{X1} and \textbf{X2} will be from \[\textbf{1}, \textbf{5}\]. The first sample is taken from the figure above. So look at the sample for exact format. \OutputFile For each case, output the case number followed by the total amount of ink requried with \textbf{2} digits after the decimal point. If the lines can't be drawn without lifting the pen then print \textbf{~x(} instead.
Time limit 1 second
Memory limit 64 MiB
Input example #1
2
4
A1 C2
B3 C3
C4 C2
C2 D2
2
A1 A5
E1 E5
Output example #1
Case 1: 8.24
Case 2: ~x(