Charlie the Cockchafer
InterviewTime limit1sMemory limit128 MB
Find the fastest route on a 3D segment network where cost combines travel distance and turn angles between consecutive segments.
- Level
Medium7 of 10
- Topics
- Graph, Shortest path, Geometry, Implementation
- Solved
- No attempts yet
Problem
Charlie knows how to fly. Even so, moving from one point to another is a tedious chore for him, because Charlie is a cockchafer — and it is well known that every cockchafer (do not confuse them with cockroaches) is clumsy and slow. They need time not only to fly along a straight line, but also, and even more so, to make turns. Knowing these limitations, can you help Charlie find the fastest route?
Input
The input consists of several instances and continues until the end of the file.
The first line of each instance contains three integers , , and (, ), where is the number of straight flight trajectories (called cockridors), is Charlie's flying speed in meters per second, and is his turning speed in degrees per second.
The second line contains six integers (), giving the starting point and the destination .
Each of the next lines contains six integers (), describing a cockridor: a line segment joining and . No interior point of any segment is an endpoint of another segment, and both the start and the destination are endpoints of at least one segment. All coordinates are given in meters.
Output
For each instance, print on its own line the minimum time that Charlie needs to travel from the start to the destination, rounded to exactly 4 digits after the decimal point.
Charlie may fly only along whole segments, and every segment may be used in either direction. The time of a route is seconds, where is the total length of the traversed segments (in meters) and is the total of the turning angles between consecutive segments (in degrees). You may freely choose Charlie's initial and final facing direction, so there is no turning cost before the first segment or after the last one. A path from the start to the destination is guaranteed to exist.