Statistics

Problem Statement for "KnockoutTourney"

Problem Statement

You have just entered a knockout tournament with N competitors. The tournament is structured as follows: at the start, the competitors are written down in a list. Adjacent competitors in the list are then paired off, starting from the first competitor on the list, and each pair plays a match (competitor 1 plays against 2, 3 plays against 4, etc.). The losers of each match are eliminated and their names are crossed off the list, while the winners progress to the next round. If there are an odd number of competitors in a round, then the last competitor in the list advances to the next round automatically, without having to play a match. This process then repeats with the new list of competitors, until only a single competitor remains, who is declared the winner. Note that the ordering of the competitors is preserved between rounds.

Your arch-rival has also entered the tournament and you want to know when you might end up playing against him. Your position in the list for the first round is you and your rival's position is rival (both indexed from 1). Assuming that both you and your rival win all the matches before you play each other, return the number of the round in which you will meet (counting the rounds from 1).

Definition

Class:
KnockoutTourney
Method:
meetRival
Parameters:
int, int, int
Returns:
int
Method signature:
int meetRival(int N, int you, int rival)
(be sure your method is public)

Constraints

  • N will be between 2 and 100000, inclusive.
  • you and rival will each be between 1 and N, inclusive.
  • you and rival will be distinct.

Examples

  1. 16

    1

    2

    Returns: 1

    This is a 4 round tournament, with 16 players, so every player plays a match in every round. You are paired with your rival in the first round.

  2. 16

    8

    9

    Returns: 4

    Despite being adjacent in the list, you are not paired with your rival until the final round.

  3. 1000

    20

    31

    Returns: 4

  4. 65536

    1000

    35000

    Returns: 16

  5. 60000

    101

    891

    Returns: 10

  6. 22179

    20695

    13642

    Returns: 15

  7. 7470

    32

    3599

    Returns: 12

  8. 5465

    1097

    2191

    Returns: 12

  9. 25905

    15364

    13876

    Returns: 12

  10. 32332

    10747

    25408

    Returns: 15

  11. 27113

    18492

    3937

    Returns: 15

  12. 22829

    6868

    17061

    Returns: 15

  13. 4805

    1038

    3555

    Returns: 12

  14. 18881

    1349

    8675

    Returns: 14

  15. 16614

    11673

    4493

    Returns: 14

  16. 18690

    5178

    9086

    Returns: 14

  17. 4567

    3170

    2409

    Returns: 11

  18. 13880

    2443

    10440

    Returns: 14

  19. 17960

    8781

    281

    Returns: 14

  20. 31465

    19518

    15883

    Returns: 15

  21. 30505

    8313

    26107

    Returns: 15

  22. 21190

    3939

    3334

    Returns: 10

  23. 28220

    19615

    14928

    Returns: 15

  24. 9428

    8183

    6497

    Returns: 11

  25. 13674

    5939

    9232

    Returns: 14

  26. 3452

    325

    1459

    Returns: 11

  27. 11341

    1633

    4121

    Returns: 13

  28. 20821

    16283

    4661

    Returns: 14

  29. 23908

    2998

    7072

    Returns: 13

  30. 32447

    12872

    23083

    Returns: 15

  31. 20333

    19357

    6940

    Returns: 15

  32. 6302

    4373

    6204

    Returns: 12

  33. 27491

    6132

    9031

    Returns: 14

  34. 20199

    8501

    12532

    Returns: 13

  35. 6946

    4552

    6119

    Returns: 11

  36. 6581

    1775

    1405

    Returns: 10

  37. 19944

    9204

    5983

    Returns: 14

  38. 4635

    2967

    4474

    Returns: 13

  39. 26415

    10463

    11071

    Returns: 10

  40. 12279

    6076

    4719

    Returns: 11

  41. 4494

    842

    4253

    Returns: 13

  42. 13931

    1951

    5717

    Returns: 13

  43. 21156

    883

    3474

    Returns: 12

  44. 8399

    6677

    275

    Returns: 13

  45. 24124

    951

    12786

    Returns: 14

  46. 24622

    11206

    4898

    Returns: 14

  47. 22056

    6127

    3996

    Returns: 13

  48. 15798

    4549

    13812

    Returns: 14

  49. 12684

    5073

    1971

    Returns: 13

  50. 20638

    6531

    2660

    Returns: 13

  51. 16773

    3253

    8915

    Returns: 14

  52. 13933

    12521

    1280

    Returns: 14

  53. 634

    69

    203

    Returns: 8

  54. 12977

    2618

    10958

    Returns: 14

  55. 28788

    507

    23593

    Returns: 15

  56. 35772

    19909

    28276

    Returns: 14

  57. 85333

    74710

    81786

    Returns: 13

  58. 92474

    87470

    45897

    Returns: 17

  59. 72055

    55469

    57183

    Returns: 11

  60. 89464

    37596

    71464

    Returns: 17

  61. 23309

    1441

    20998

    Returns: 15

  62. 675

    440

    152

    Returns: 9

  63. 35129

    25712

    29707

    Returns: 13

  64. 5199

    4095

    530

    Returns: 12

  65. 70677

    50736

    4140

    Returns: 16

  66. 100000

    1

    10000

    Returns: 14

  67. 43532

    353

    2355

    Returns: 12

  68. 3

    3

    1

    Returns: 2

  69. 3

    3

    2

    Returns: 2

  70. 5

    5

    1

    Returns: 3

  71. 101

    13

    51

    Returns: 6

  72. 9

    1

    9

    Returns: 4

  73. 9

    8

    9

    Returns: 4

  74. 1000

    8

    9

    Returns: 4

  75. 6

    5

    2

    Returns: 3

  76. 1000

    4

    3

    Returns: 1

  77. 10000

    10000

    1

    Returns: 14

  78. 10

    1

    9

    Returns: 4

  79. 30

    27

    3

    Returns: 5

  80. 16

    2

    1

    Returns: 1

  81. 100000

    321

    99999

    Returns: 17

  82. 100000

    1

    100000

    Returns: 17

  83. 9

    2

    1

    Returns: 1

  84. 49

    20

    21

    Returns: 3

  85. 8

    4

    5

    Returns: 3

  86. 1000

    2

    1

    Returns: 1

  87. 1000

    7

    8

    Returns: 1

  88. 2

    2

    1

    Returns: 1

  89. 13

    12

    13

    Returns: 3

  90. 7

    6

    5

    Returns: 1

  91. 100000

    2

    3

    Returns: 2

  92. 16

    14

    15

    Returns: 2

  93. 13

    2

    3

    Returns: 2

  94. 2

    1

    2

    Returns: 1

  95. 4

    2

    1

    Returns: 1

  96. 100

    100

    1

    Returns: 7

  97. 5

    4

    5

    Returns: 3

  98. 6

    5

    1

    Returns: 3

  99. 100000

    8

    9

    Returns: 4

  100. 11

    5

    6

    Returns: 1

  101. 15

    15

    1

    Returns: 4

  102. 100

    49

    51

    Returns: 2

  103. 9999

    5001

    7

    Returns: 13

  104. 16

    16

    14

    Returns: 2

  105. 4

    2

    3

    Returns: 2

  106. 10

    10

    1

    Returns: 4

  107. 20

    9

    10

    Returns: 1

  108. 10

    5

    6

    Returns: 1

  109. 17

    17

    1

    Returns: 5

  110. 5

    2

    1

    Returns: 1

  111. 98997

    76579

    26

    Returns: 17

  112. 10000

    3

    2

    Returns: 2

  113. 65535

    64

    65534

    Returns: 16

  114. 7

    4

    7

    Returns: 3

  115. 16

    7

    9

    Returns: 4

  116. 16

    10

    1

    Returns: 4

  117. 10

    7

    8

    Returns: 1

  118. 5

    1

    5

    Returns: 3

  119. 3

    1

    3

    Returns: 2

  120. 100000

    5681

    99999

    Returns: 17


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: