Statistics

Problem Statement for "TwoKings"

Problem Statement

A white queen and two black kings are placed on a 100 x 100 chessboard. White and black sides move by turns. The white queen moves first (only one of the two black kings is moved on each turn). Given three Strings, queen, king1 and king2, return the minimal number of white moves needed to capture one of the kings (kings are not allowed to capture the queen, and may not move to the queen's location). queen, king1 and king2 will each contain the 0-based row and column of the corresponding piece.

Definition

Class:
TwoKings
Method:
captureKing
Parameters:
String, String, String
Returns:
int
Method signature:
int captureKing(String queen, String king1, String king2)
(be sure your method is public)

Notes

  • The black side tries to avoid capturing as long as possible.
  • Kings move one cell in any direction, horizontally, vertically, or diagonally.
  • The queen moves any number of cells in any direction, horizontally, vertically, or diagonally.
  • The queen captures a king if it moves to the cell that the king occupies.
  • Neither side can skip a turn.
  • Pieces may not move off the board.

Constraints

  • queen, king1 and king2 will each contain two space-delimited integers between 0 and 99, inclusive.
  • The numbers in queen, king1 and king2 will not contain leading zeroes.
  • No two pieces will occupy the same cell.

Examples

  1. "0 0"

    "1 1"

    "99 99"

    Returns: 1

    You can capture a king on the first turn.

  2. "0 0"

    "99 0"

    "0 99"

    Returns: 1

    You can capture any king on the first turn.

  3. "1 1"

    "90 0"

    "0 30"

    Returns: 2

  4. "98 98"

    "0 97"

    "99 0"

    Returns: 2

    You can move to the "0 0" cell and threaten both kings. You will capture one of them on the next turn.

  5. "99 0"

    "1 1"

    "0 98"

    Returns: 2

  6. "99 10"

    "80 80"

    "50 1"

    Returns: 4

  7. "0 0"

    "35 57"

    "48 49"

    Returns: 4

  8. "49 48"

    "35 57"

    "0 0"

    Returns: 2

  9. "0 0"

    "4 5"

    "30 80"

    Returns: 4

  10. "46 99"

    "74 16"

    "15 1"

    Returns: 4

  11. "16 35"

    "53 36"

    "23 40"

    Returns: 3

  12. "15 48"

    "43 26"

    "4 31"

    Returns: 2

  13. "57 79"

    "72 35"

    "92 0"

    Returns: 2

  14. "70 83"

    "72 87"

    "52 18"

    Returns: 4

  15. "82 99"

    "60 12"

    "72 13"

    Returns: 4

  16. "11 9"

    "94 46"

    "61 75"

    Returns: 4

  17. "8 54"

    "64 89"

    "38 61"

    Returns: 4

  18. "43 58"

    "8 68"

    "80 37"

    Returns: 4

  19. "96 72"

    "87 69"

    "90 20"

    Returns: 2

  20. "70 1"

    "34 74"

    "77 58"

    Returns: 4

  21. "60 96"

    "11 44"

    "17 22"

    Returns: 4

  22. "65 65"

    "20 62"

    "95 28"

    Returns: 4

  23. "44 11"

    "25 99"

    "68 95"

    Returns: 3

  24. "97 42"

    "29 42"

    "36 24"

    Returns: 1

  25. "25 2"

    "55 3"

    "57 51"

    Returns: 3

  26. "86 58"

    "96 78"

    "16 96"

    Returns: 4

  27. "53 53"

    "65 81"

    "67 54"

    Returns: 3

  28. "20 58"

    "38 21"

    "2 25"

    Returns: 4

  29. "56 23"

    "86 79"

    "44 96"

    Returns: 4

  30. "47 57"

    "79 6"

    "44 41"

    Returns: 2

  31. "53 90"

    "35 86"

    "47 10"

    Returns: 4

  32. "43 25"

    "39 44"

    "78 2"

    Returns: 4

  33. "91 34"

    "55 50"

    "33 82"

    Returns: 4

  34. "37 10"

    "26 68"

    "37 3"

    Returns: 1

  35. "22 62"

    "56 63"

    "28 95"

    Returns: 3

  36. "59 65"

    "39 27"

    "30 80"

    Returns: 2

  37. "95 22"

    "91 2"

    "87 47"

    Returns: 4

  38. "5 75"

    "43 99"

    "29 18"

    Returns: 2

  39. "22 53"

    "95 64"

    "30 76"

    Returns: 4

  40. "0 0"

    "9 9"

    "1 1"

    Returns: 1

  41. "10 9"

    "0 0"

    "20 30"

    Returns: 2

  42. "0 15"

    "11 9"

    "10 20"

    Returns: 2

  43. "20 80"

    "21 15"

    "0 99"

    Returns: 2

  44. "20 80"

    "39 61"

    "0 99"

    Returns: 1

  45. "5 95"

    "0 13"

    "13 18"

    Returns: 2

  46. "5 95"

    "0 13"

    "13 19"

    Returns: 3

  47. "95 95"

    "1 0"

    "0 1"

    Returns: 2

  48. "45 73"

    "88 12"

    "11 42"

    Returns: 4

  49. "99 0"

    "1 1"

    "0 47"

    Returns: 2

  50. "99 0"

    "1 1"

    "1 47"

    Returns: 2

  51. "55 30"

    "53 22"

    "11 64"

    Returns: 2

  52. "40 53"

    "47 68"

    "48 34"

    Returns: 3

  53. "31 3"

    "59 64"

    "60 12"

    Returns: 3

  54. "15 29"

    "76 32"

    "74 49"

    Returns: 3

  55. "62 90"

    "91 36"

    "95 35"

    Returns: 3

  56. "22 53"

    "95 64"

    "30 76"

    Returns: 4

  57. "64 75"

    "12 20"

    "25 9"

    Returns: 3

  58. "87 44"

    "89 0"

    "83 59"

    Returns: 3

  59. "1 2"

    "0 0"

    "60 80"

    Returns: 2

  60. "2 99"

    "0 1"

    "1 0"

    Returns: 2


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: