eolymp
bolt
Try our new interface for solving problems
Məsələlər

M M Detour

M M Detour

Metro Manila currently has five circumferential roads arranged in concentric semicircles, with a sixth to be constructed linking the north and the south. From the center (Manila), there are ten radial roads that link the inner and outer areas of Metro Manila. \includegraphics{https://static.e-olymp.com/content/32/32bdc32e619120fb27254b2e35e518d15fd768fa.jpg} \textit{\textbf{Figure 1}} Ideal road network of Metro Manila In this problem, we are to find the shortest distance to get from point \textbf{A} to point \textbf{B}. Each point is defined by the intersection of a circumferential and radial road pair (\textbf{C#}, \textbf{R#}) with the center represented as (\textbf{C0}, \textbf{R0}). For calculation purposes, the distance for each segment in the radial road is equal to \textbf{1} unit, while each arc is equal to the circumferential road number. For instance, the distance from (\textbf{C1}, \textbf{R3}) to (\textbf{C2}, \textbf{R3}) is one unit, and the distance from (\textbf{C3}, \textbf{R1}) to (\textbf{C3}, \textbf{R2}) is three units. The shortest distance from (\textbf{C1}, \textbf{R2}) to (\textbf{C5}, \textbf{R1}) is five units (See darkened path). It is assumed that \textbf{C6} is passable for this problem. However with the new number coding scheme, vehicles are not allowed to use the radial roads with the same last digit of the plate numbers. For instance, a vehicle with plate number of \textbf{ABC-123} cannot use \textbf{R3}. Furthermore, the circumferential roads (except for \textbf{C6}) also have restrictions. Plate numbers ending in \textbf{1} and \textbf{2} are not allowed in \textbf{C1}, \textbf{3 }and \textbf{4} in \textbf{C2}, \textbf{5} and \textbf{6} in \textbf{C3}, \textbf{7} and \textbf{8} in \textbf{C4}, and \textbf{9} and \textbf{0} in \textbf{C5}. Thus the shortest path from (\textbf{C1}, \textbf{R2}) to (\textbf{C5}, \textbf{R1}) for vehicle with plate number \textbf{ABC-123} is five units, but nine units for vehicle with plate number \textbf{CBA-321}. Note that there will be instances that a vehicle cannot reach the destination at all. \InputFile The input consists of multiple test cases. For simplicity, each test case will have \textbf{5} single digit numbers that are whitespace separated. The first two numbers represent the starting point, the next two numbers represent the destination point, and the last number is the ending digit of the plate number. There are no blank lines in between test cases, and the last test case is followed by a line containing a single zero. \OutputFile For each test case, print the case number (starting with \textbf{1}) followed by the shortest distance needed. Output "\textbf{not possible}" if the destination cannot be reached.
Zaman məhdudiyyəti 5 saniyə
Yaddaşı istafadə məhdudiyyəti 128 MiB
Giriş verilənləri #1
1 2 5 1 3
1 2 5 1 1
0
Çıxış verilənləri #1
Case 1: 5
Case 2: 9
Mənbə ACM ICM Philippines Multi-Provincial Programming Contest 2013