TopcoderArchiveVisit Topcoder
TCO31 Mar 2017
TCO17 Austin

AroundTheWall

Problem statement, definition, constraints, and public examples.

Problem Statement

Consider the XY plane. The non-negative part of the X axis is a wall. (In other words, the wall is a ray that starts in the point (0, 0) and goes indefinitely in the positive X direction.
There is a robot in the plane. The robot is a circle of radius r. Initially the center of the robot is at the coordinates (x1, y1). The robot needs to move its center to the point (x2, y2). The robot cannot go through the wall, but it can touch the wall at any point.
Compute and return the minimal distance the robot needs to travel.

Definition

Class:
AroundTheWall
Method:
minDistance
Parameters:
int, int, int, int, int
Returns:
double
Method signature:
double minDistance(int r, int x1, int y1, int x2, int y2)
(be sure your method is public)

Notes

  • The returned value must have an absolute or relative error less than 1e-9.

Constraints

  • x1, y1, x2 and y2 will each be between -1000 and 1000, inclusive.
  • r will be between 1 and 50, inclusive.
  • Points (x1, y1) and (x2, y2) will be distinct.
  • Both points (x1, y1) and (x2, y2) will be at distance at least r from the wall.

Examples

  1. 1
    1
    2
    -2
    0
    Returns: 3.605551275463989
    The robot can move in a straight line between the two points, safely avoiding the wall. It will cover a distance of sqrt(22+32) = sqrt(13).
  2. 5
    -7
    -1
    1
    7
    Returns: 11.41897054604164
    The wall prevents the robot from moving straight between the two points.
  3. 5
    1
    7
    -1
    -7
    Returns: 17.853981633974485
    The robot has to make a 90-degree turn to go around the wall.
  4. 25
    -7
    24
    -15
    -20
    Returns: 55.35743588970452
Back to all problems