Jack and Jill (1 Point)

View as PDF

Submit solution

Points: 100
Time limit: 1.0s
Memory limit: 256M

Author:
Problem type

Jack and Jill

Jack and Jill went up the hill Swapping neighbour numbers. With n at 11 and k at 7, Jack felt unencumbered.

To his dismay, Jill did play, A rather cunning game. One by one, the numbers come, With victory there to claim

Next came 1, the game not done And with that the air had tensed. With Jack to play, 10 he did say But their difference, too immense!

Jack and Jill are climbing up a hill, and to pass the time they are playing a game of neighbour numbers. In the game, they start by picking two values, n and k. The game then consists of them taking turns saying numbers from 1 to n.

There are only two rules in neighbour numbers:

  • No number can be repeated
  • For the ith turn, that number must have a distance of k or less from the i-1th number.

In this problem, we are Jill, and we'll simply be implementing a player for the game of neighbour numbers. We don't need to win, just not to make any illegal moves.

Interaction

This problem is interactive, which means you will need to collect input and print output multiple times.

The interaction will start with a line containing two space-separated integers, n and k. Next, you should output a single integer, your first move in the game. Each time you print an integer, the judge will then respond with another integer.

You should interact in one of three possible ways:

  • If their move was invalid, print "I win!", and the program ends.
  • If you have no possible move, "You win!", and the program ends.
  • Otherwise, print a valid integer response, and interaction continues.

Interaction Examples

Example 1: Jack (judge) prints an invalid answer
[Jack]: 5 2
[Jill]: 3
[Jack]: 1
[Jill]: 2
[Jack]: 5
[Jill]: I win!

This is invalid because 5 and 2 are distance 3 (>k=2) distance apart.

Example 2: Jill has no response
[Jack]: 10 1
[Jill]: 2
[Jack]: 1
[Jill]: You win!

Interaction Template (Python)

# Alternatively, this can be done with
# n, k = list(map(int, input().split()))
n_str, k_str = input().split()
n, k = int(n_str), int(k_str)

first_num = ...
# Jill's first number
print(first_num)
# Judge's first number
judge_response = int(input())
# Jill's response
print(...)

Constraints

  • 1 \leq n \leq 10^3
  • 1 \leq k \leq 10^2
  • Every integer answer from Jack will be a number from 1 to n.

Comments

There are no comments at the moment.