Statistics

Problem Statement for "GameOfSegments"

Problem Statement

Rijél is a very wise teacher. He loves mathematics, especially games and geometry problems. Recently one of his students challenged him to the following game:


Initially, there is a polygon with N vertices drawn in the plane. The polygon is strictly convex, i.e., each internal angle is strictly smaller than 180 degrees. The vertices of the polygon are numbered 1 through N, in clockwise order.


Two players play the game on this polygon. The players take alternating turns. In each turn, the current player chooses a diagonal or a side of the polygon and draws it as a straight line segment. (A diagonal of the polygon is a line segment that connects any two non-adjacent vertices of the polygon.) The player is only allowed to choose a diagonal or a side that does not intersect any of the previously drawn segments (it must not share endpoints with any of them either). The player who cannot draw a diagonal or a side according to the above rules loses the game.


You are given the int N.


We assume that both players play the game optimally. Return 1 if the first player wins and 2 otherwise.

Definition

Class:
GameOfSegments
Method:
winner
Parameters:
int
Returns:
int
Method signature:
int winner(int N)
(be sure your method is public)

Constraints

  • N will be between 3 and 1,000, inclusive.

Examples

  1. 3

    Returns: 1

    This polygon has zero diagonals and three sides. The first player will always win no matter which side he picks.

  2. 4

    Returns: 1

    This polygon has four sides and two diagonals. The first player wins the game if he takes one of the diagonals, because he will leave no choice for the second player.

  3. 498

    Returns: 1

  4. 887

    Returns: 1

  5. 854

    Returns: 1

  6. 15

    Returns: 2

  7. 882

    Returns: 1

  8. 621

    Returns: 2

  9. 896

    Returns: 1

  10. 792

    Returns: 1

  11. 265

    Returns: 1

  12. 191

    Returns: 2

  13. 584

    Returns: 1

  14. 34

    Returns: 1

  15. 848

    Returns: 1

  16. 778

    Returns: 1

  17. 413

    Returns: 2

  18. 521

    Returns: 1

  19. 302

    Returns: 1

  20. 842

    Returns: 1

  21. 356

    Returns: 1

  22. 520

    Returns: 1

  23. 197

    Returns: 1

  24. 781

    Returns: 1

  25. 274

    Returns: 1

  26. 663

    Returns: 1

  27. 393

    Returns: 1

  28. 856

    Returns: 1

  29. 858

    Returns: 1

  30. 59

    Returns: 2

  31. 996

    Returns: 1

  32. 577

    Returns: 1

  33. 425

    Returns: 1

  34. 400

    Returns: 1

  35. 861

    Returns: 1

  36. 733

    Returns: 1

  37. 745

    Returns: 1

  38. 409

    Returns: 1

  39. 873

    Returns: 1

  40. 827

    Returns: 1

  41. 83

    Returns: 1

  42. 967

    Returns: 1

  43. 507

    Returns: 1

  44. 704

    Returns: 1

  45. 248

    Returns: 1

  46. 145

    Returns: 2

  47. 745

    Returns: 1

  48. 356

    Returns: 1

  49. 746

    Returns: 1

  50. 459

    Returns: 1

  51. 879

    Returns: 2

  52. 11

    Returns: 1

  53. 999

    Returns: 1

  54. 7

    Returns: 1

  55. 10

    Returns: 1

  56. 929

    Returns: 1

  57. 997

    Returns: 1

  58. 246

    Returns: 1

  59. 1000

    Returns: 1

  60. 6

    Returns: 1

  61. 925

    Returns: 1

  62. 5

    Returns: 2

  63. 987

    Returns: 1

  64. 190

    Returns: 1

  65. 891

    Returns: 1

  66. 700

    Returns: 1

  67. 8

    Returns: 1

  68. 777

    Returns: 2

  69. 25

    Returns: 2

  70. 24

    Returns: 1

  71. 903

    Returns: 1

  72. 816

    Returns: 1

  73. 37

    Returns: 1

  74. 9

    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: