Connection Status:
Competition Arena > PointDistance
SRM 667 · 2015-08-28 · by lg5293 · Brute Force, Geometry
Class Name: PointDistance
Return Type: int[]
Method Name: findPoint
Arg Types: (int, int, int, int)
Problem Statement

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.

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
0)
-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.

1)
1
1
-1
-1
Returns: {25, -63 }

(x1,y1) is (1,1) and (x2,y2) is (-1,-1).

2)
0
1
2
3
Returns: {41, 65 }
3)
5
-4
-2
5
Returns: {68, 70 }
4)
-50
-50
50
-50
Returns: {67, 4 }

Submissions are judged against all 82 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PointDistance with a public method vector<int> findPoint(int x1, int y1, int x2, int y2) · 82 test cases · 2 s / 256 MB per case

Submitting as anonymous