PointDistance
SRM 667 · 2015-08-28 · by lg5293
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
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).
-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
Returns: {25, -63 }
(x1,y1) is (1,1) and (x2,y2) is (-1,-1).
0
1
2
3
Returns: {41, 65 }
5
-4
-2
5
Returns: {68, 70 }
-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.
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