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

I`ll Be Round About

I`ll Be Round About

\includegraphics{https://static.e-olymp.com/content/f1/f130d058d1680dae4c3a37669c3f99f6f40ce1cd.jpg} A common traffic intersection in Europe, and one that is becoming popular in the United States, is the "roundabout". When a driver enters a roundabout, the driver yields to cars that are already in the roundabout, then proceeds in and around to the correct exit. Roundabouts may have multiple lanes entering, circling, and exiting the traffic structure, which contains a center area that is usually circular. In the U.S. the cars travel in a counter-clockwise direction, while in the United Kingdom and areas where the norm is to drive on the left, the cars circle in a clockwise manner. A particular country, Roundoslavia, uses roundabouts for all road intersections. Also, because roundabouts are so popular, the government has decided that the center circle could be fairly large. They plan on placing parks in the center. This presents a problem for the tourism bureau at Roundoslavia; the distance between two points on a map, something that they would like to print in the tourism guides, will be longer because of the increased distance at the intersections. Roundoslavians drive on the right side of the road, so they proceed in a counter-clockwise direction. Thus a car entering the intersection from the right (East) and exiting at the bottom (South) would make three-quarters (\textbf{¾}) of a circle. If the center island is \textbf{500} meters in diameter, the car will have travelled \textbf{¾} the circumference of a circle \textbf{500 }meters across. In general if we consider East to be \textbf{0} degrees, North to be \textbf{90} degrees, West to be \textbf{180} degrees, and so on, we can restate this as "the car enters from zero degrees and exits at \textbf{270} degrees." Roundabouts are placed to minimize the amount of road that is needed between them, so cars may enter at an arbitrary point, say \textbf{48} degrees, and exit at \textbf{190} degrees. Also, other cars could be entering at \textbf{190} and exiting at \textbf{48}. When calculating the distances between locations on a map, the travel bureau wishes to include these extra roundabout travel distances so that the visitors to the country have an accurate estimate of how long their driving times will be. Given data on a set of roundabouts, the roads connecting them, and the starting and ending roundabouts, determine the minimum distance between the starting and ending roundabouts and the corresponding route. The correct route will always be unique. \InputFile There will be an arbitrary number of cases to consider. The input begins with a line containing a single integer that specifies the number of cases. That line is followed by the input for the first case, then the input for the second case, and so forth. The input for each case begins with a line containing a single integer \textbf{NRB} (\textbf{1} ≤ \textbf{NRB} ≤ \textbf{25}) which is the number of roundabouts. This line is followed by \textbf{NRB} lines, with the \textbf{I}-th line (\textbf{1} ≤ \textbf{I} ≤ \textbf{NRB}) giving the diameter of the I-th roundabout, in meters. The next line in the input for each case contains a single integer \textbf{NRD} (\textbf{1} ≤ \textbf{NRD} ≤ \textbf{100}) which is the number of roads connecting the roundabouts. This line is followed by \textbf{NRD} lines (that is, one for each road), each containing five (\textbf{5}) integers separated by one or more spaces. The first two integers identify the roundabouts that are connected by the road. The third integer gives the length of the road, in meters, but does not include any of the distance that might be travelled inside the roundabouts. The fourth integer specifies the angle (in degrees) at which the road connects to the roundabout specified by the first integer. Similarly, the fifth integer specifies the angle at which the road connects to the roundabout specified by the second integer. The angles will always be non-negative and less than \textbf{360} degrees. The last line in the input for each case contains two integers separated by whitespace. These integers identify the starting and ending roundabouts between which the minimum distance and corresponding route are to be determined. Roads may curve slightly; leaving a roundabout at 90 degrees does not necessarily imply entry to another at \textbf{270} degrees. We are not concerned with this. Also, there are no one-way roads, and there is at most one road directly connecting any pair of roundabouts. In determining the distance traveled within a single roundabout, the calculation should be done using real numbers, and then truncated to yield an integer. No "U-turns" are permitted at the entrance to a roundabout. To enter and exit at the same angle, the driver must go all the way around---\textbf{360} degrees. \textit{\textbf{Example}}: Consider the input shown in the Sample Input (below). There are two cases to consider. The first case has \textbf{9} roundabouts (with diameters \textbf{500}, \textbf{450}, …, \textbf{1500}) and \textbf{12} roads. The first road connects roundabouts \textbf{6} and \textbf{1}, and has a distance of \textbf{15000} meters. It connects to roundabout \textbf{6} at \textbf{0} degrees, and to roundabout \textbf{1} at \textbf{180} degrees. For this case, you are to find the appropriate route between roundabouts \textbf{6} and \textbf{9}. Note that there is no extra distance associated with entering or leaving the endpoints. In the first example case, initially leaving roundabout six adds no additional distance, and entering roundabout nine also adds no additional distance. As a simple example, suppose you were asked for the distance between roundabouts one and six. This would be just \textbf{15000} meters. As another example, the distance from one to one is zero meters. The route in this case is \textbf{1}. \OutputFile For each input case, print the case number (\textbf{1}, \textbf{2}, …), the distance between the starting and ending points, and the route using the format shown. Indent the "\textbf{Distance: }" and "\textbf{Path: }" lines three spaces, and include a blank line as the last line in the output for each case. Follow the format shown.
Zaman məhdudiyyəti 1 saniyə
Yaddaşı istafadə məhdudiyyəti 64 MiB
Giriş verilənləri #1
2
9
500
450
600
1000
950
800
1200
700
1500
12
6 1 15000 0 180
6 3 40000 290 120
1 2 60000 10 190
2 3 70000 210 45
3 5 45000 270 90
5 8 78000 330 170
3 4 36000 10 190
8 4 78000 70 220
2 4 18000 280 100
2 7 68900 350 170
4 7 60000 40 220
4 9 95000 330 120
6 9
5
700
900
250
1000
750
7
1 2 10000 10 45
2 3 20000 30 0
1 5 10000 180 90
2 5 5000 45 200
2 4 40000 35 20
5 4 35000 200 300
3 4 30000 125 65
1 4
Çıxış verilənləri #1
Case 1:
   Distance: 173529
   Route: 6,3,4,9

Case 2:
   Distance: 45719
   Route: 1,5,4

Mənbə ACM North Central North America Regional Programming Contest, November 12, 2011