TopcoderArchiveVisit Topcoder
SRM28 Aug 2015
SRM 667

PointDistance

Problem statement, definition, constraints, and public examples.

Problem Statement

You are given two distinct points A and B in the two-dimensional plane. Your task is to find any point C with the following properties:

  • C is different from A and B.
  • Each coordinate of C is an integer between -100 and 100, inclusive.
  • The distance between A and C is strictly greater than the distance between B and C.

You are given four ints: x1, y1, x2, and y2. Point A has coordinates (x1,y1) and point B has coordinates (x2,y2). Find the coordinates (x3,y3) of one possible point C with the above properties. Return these coordinates as a int[] with two elements: element 0 is x3 and element 1 is y3. In other words, return the int[] {x3,y3}.

For the constraints given below it is guaranteed that a valid point C always exists. If there are multiple solutions, return any of them.

Definition

Class:
PointDistance
Method:
findPoint
Parameters:
int, int, int, int
Returns:
int[]
Method signature:
int[] findPoint(int x1, int y1, int x2, int y2)
(be sure your method is public)

Notes

  • In this problem we consider the standard Euclidean distance. Formally, the distance between points (xi,yi) and (xj,yj) is defined as sqrt( (xi-xj)^2 + (yi-yj)^2 ).

Constraints

  • x1,y1,x2,y2 will be between -50 and 50, inclusive.
  • (x1,y1) will be different from (x2,y2).

Examples

  1. -1
    0
    1
    0
    Returns: {8, 48 }
    In this example, point A is at (-1,0) and point B is at (1,0). Almost any point with a positive x-coordinate will be a valid answer. For example, your program can also return {100,100}, {2,0}, or {9,-100}. Note that you cannot return {1,0} because point C must not be the same as point B.
  2. 1
    1
    -1
    -1
    Returns: {25, -63 }
    (x1,y1) is (1,1) and (x2,y2) is (-1,-1).
  3. 0
    1
    2
    3
    Returns: {41, 65 }
  4. 5
    -4
    -2
    5
    Returns: {68, 70 }
  5. -50
    -50
    50
    -50
    Returns: {67, 4 }
  6. -50
    50
    -49
    49
    Returns: {73, -25 }
Back to all problems