shortestpathcube
InterviewTime limit1sMemory limit512 MB
Find the shortest path along the surface of a 100 by 100 by 100 cube from a given surface point to the opposite corner.
- Level
Medium6 of 10
- Topics
- Geometry, Shortest path, Math, Implementation
- Solved
- No attempts yet
Problem
Write a function P3:
-
A point P on the surface of a cube C whose faces are parallel to the coordinate planes and which has (0, 0, 0) and (100, 100, 100) as vertices.
-
input parameter:
x,y,zsuch that the point P(x,y,z) lies on the surface of C- Each of
x,y,zis either an integer or a float.
- Each of
-
return value: the minimum distance from (
x,y,z) to (100, 100, 100) under the following restrictions:- You must stay on the surface of C.
- You can move to a different face by passing through an edge.
- The answer must have an absolute or relative error less than 10−6.