Statistics

Problem Statement for "PointDistance"

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 }

  7. -13

    7

    -12

    33

    Returns: {-10, 90 }

  8. 33

    -30

    -38

    -1

    Returns: {-98, 62 }

  9. 0

    36

    -25

    -39

    Returns: {-71, -79 }

  10. 14

    -22

    -30

    14

    Returns: {-94, -96 }

  11. 29

    -1

    -6

    -30

    Returns: {-98, 31 }

  12. -22

    36

    21

    -16

    Returns: {37, -4 }

  13. -47

    -42

    -5

    19

    Returns: {11, 73 }

  14. -14

    -39

    0

    16

    Returns: {-74, 79 }

  15. 12

    33

    40

    19

    Returns: {81, -5 }

  16. 38

    -8

    39

    19

    Returns: {20, 95 }

  17. -42

    10

    10

    -28

    Returns: {-8, -61 }

  18. -44

    -44

    31

    39

    Returns: {-16, 22 }

  19. -47

    -26

    7

    3

    Returns: {81, 11 }

  20. 34

    -47

    -26

    19

    Returns: {80, 86 }

  21. -15

    39

    15

    7

    Returns: {-16, -87 }

  22. 25

    27

    -20

    -38

    Returns: {-53, 31 }

  23. -12

    13

    -25

    -22

    Returns: {-31, -7 }

  24. -14

    -25

    27

    1

    Returns: {72, 92 }

  25. -19

    26

    -19

    -42

    Returns: {80, -37 }

  26. -23

    32

    -24

    10

    Returns: {3, -29 }

  27. 42

    -25

    -12

    33

    Returns: {0, 60 }

  28. -19

    14

    -31

    28

    Returns: {2, 62 }

  29. 21

    6

    14

    -34

    Returns: {18, -94 }

  30. 14

    18

    -31

    -42

    Returns: {-100, -21 }

  31. 18

    7

    -39

    49

    Returns: {-36, 30 }

  32. 21

    17

    12

    -33

    Returns: {58, -19 }

  33. 7

    -12

    -13

    2

    Returns: {21, 44 }

  34. -14

    -23

    -5

    6

    Returns: {56, 3 }

  35. -32

    -12

    7

    -42

    Returns: {72, 12 }

  36. 5

    9

    16

    21

    Returns: {72, 46 }

  37. -38

    15

    8

    23

    Returns: {88, 96 }

  38. -13

    16

    19

    29

    Returns: {54, 14 }

  39. -30

    16

    2

    -35

    Returns: {58, -100 }

  40. -3

    6

    34

    -31

    Returns: {56, 26 }

  41. -36

    35

    -45

    19

    Returns: {77, -55 }

  42. -49

    -20

    15

    -28

    Returns: {53, -39 }

  43. -11

    10

    -40

    -32

    Returns: {-84, -53 }

  44. 23

    16

    1

    -16

    Returns: {-97, 27 }

  45. -19

    9

    49

    -27

    Returns: {70, -79 }

  46. 21

    -1

    -48

    -50

    Returns: {-95, -13 }

  47. 45

    1

    -45

    35

    Returns: {6, 74 }

  48. -45

    -17

    -42

    -42

    Returns: {-5, -95 }

  49. -46

    30

    -13

    17

    Returns: {40, 40 }

  50. 4

    -17

    1

    -30

    Returns: {-4, -100 }

  51. -33

    29

    47

    -14

    Returns: {98, -65 }

  52. 26

    12

    21

    5

    Returns: {91, -74 }

  53. -33

    -20

    25

    6

    Returns: {99, 42 }

  54. 7

    40

    36

    -39

    Returns: {30, -89 }

  55. -43

    29

    -43

    34

    Returns: {8, 83 }

  56. 27

    27

    -23

    -28

    Returns: {24, -94 }

  57. 50

    50

    -50

    -50

    Returns: {-61, 20 }

  58. 40

    23

    40

    22

    Returns: {-47, 11 }

  59. 10

    10

    10

    40

    Returns: {88, 41 }

  60. 1

    1

    2

    2

    Returns: {50, -42 }

  61. 0

    0

    1

    1

    Returns: {-52, 64 }

  62. 0

    1

    0

    0

    Returns: {-45, -36 }

  63. -2

    -1

    -1

    -2

    Returns: {38, -26 }

  64. 1

    0

    -1

    0

    Returns: {-79, -29 }

  65. -11

    -11

    -10

    -10

    Returns: {76, 30 }

  66. 48

    10

    46

    10

    Returns: {12, -96 }

  67. -50

    0

    50

    0

    Returns: {91, 23 }

  68. 1

    50

    2

    -50

    Returns: {-95, -64 }

  69. 1

    1

    0

    0

    Returns: {-98, 93 }

  70. 50

    50

    49

    50

    Returns: {-3, -62 }

  71. 3

    4

    -10

    3

    Returns: {-60, -24 }

  72. 49

    49

    50

    50

    Returns: {68, 95 }

  73. 10

    -1

    10

    -2

    Returns: {15, -100 }

  74. -50

    -50

    50

    50

    Returns: {98, 26 }

  75. 50

    49

    49

    50

    Returns: {-69, 95 }

  76. 5

    0

    4

    0

    Returns: {-16, 62 }

  77. 1

    -1

    -1

    1

    Returns: {-70, -49 }

  78. 0

    0

    2

    0

    Returns: {61, 3 }

  79. 1

    0

    -50

    50

    Returns: {-12, 55 }

  80. -49

    -49

    -50

    -50

    Returns: {-70, -99 }

  81. 0

    0

    0

    1

    Returns: {66, 41 }

  82. 0

    0

    2

    8

    Returns: {-86, 96 }


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: