img
Czech ACM Student Chapter
Czech Technical University in Prague
Charles University in Prague
Technical University of Ostrava
acm
ˇ ´
Slovak University of Technology
Pavol Jozef Safarik University in Koˇice
s
cz
ˇ
University of Zilina
Masaryk University
Matej Bel University in Bansk´ Bystrica
a
University of West Bohemia
CTU Open Contest 2012
Charlie the Cockchafer
cockchaf.c, cockchaf.cpp, Cockchaf.java
Charlie knows how to fly. Despite this, whenever Charlie wants to move from one point to
another, it becomes a tedious task for him. The main trouble is that Charlie is a cockchafer.
And it is a well-known fact that all cockchafers (do not confuse them with cockroaches) are
clumsy and slow. Not only they need some time to fly along a straight line, they also spend
more time making turns. Knowing their limitations, will you help Charlie to find the quickest
route?
Input Specification
The input consists of several instances. The first line of each instance contains integers N , S
and T (1 N 1000, 1 S, T 1000), where N is the number of straight cockchafer flight
trajectories (also known as "cockridors"), S is Charlie's speed in meters per second, and T is
the speed of him turning in degrees per second. The second line contains six integers (0
Xf , Yf , Zf , Xt, Yt, Zt 10000) indicating the starting point (Xf , Yf , Zf ) and the destination
(Xt, Yt, Zt).
Each of the following N lines contains six integers 0 X1, Y1, Z1, X2, Y2, Z2 10000 stating
there is a line segment (cockridor) joining points (X1, Y1, Z1) with (X2, Y2, Z2). You are guar-
anteed that no internal point of the segment is an endpoint of another segment, and that both
the initial and the final positions are endpoints of at least one of the segments. All coordinates
are given in meters.
Output Specification
For each input instance, print a single line containing one real number R, giving the shortest
time Charlie needs to get from the initial to the final point. Charlie can only move along the
whole straight segments, all of them can be used in both directions. The time for any such
path is R = L/S + D/T seconds, where L is the sum of the lengths of all segments traversed
(in meters) and D is the sum of the angles needed to turn between consecutive segments (in
degrees). You can choose the initial and final direction that Charlie is facing, and assume that
there always exists at least one path from the initial to the final point.
The answer will be accepted as correct if the difference between R and the answer computed by
the judges is at most 0.001.
Sample Input
131
000
10 10 10
000
10 10 10
231
000
10 10 10
000
0 10 10
10 10
10 0 10 10
Output for Sample Input
5.7735
98.0474