This page is still under construction.

Parts of this page are still being built. What you see may change.

shortestpathcube

Interview

Time limit1sMemory limit512 MB

Summary
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, z such that the point P(x, y, z) lies on the surface of C

    • Each of x, y, z is either an integer or a float.
  • 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.

Examples1

  1. Example 1

    Input
    0 0 0
    
    Expected output
    223.6067977500