Connection Status:
Competition Arena > PingPongQueue
TCO17 Round 1A · 2017-03-31 · by Nickolas · Simulation
Class Name: PingPongQueue
Return Type: int[]
Method Name: whoPlaysNext
Arg Types: (vector<int>, int, int)
Problem Statement

Problem Statement

This task is about a group of people who like to play ping pong. All games of ping pong mentioned in this task are one-on-one games.
You are given a int[] skills. Each element of skills is the skill level of one person in the group. The skill levels are all distinct. Whenever two people play a game of ping pong, the one with the higher skill level always wins.
All people in the group would like to play but they only have a single table. Therefore, only two people can play at any given time.
There will be a sequence of games, numbered starting from 1. Game 1 will be played by the players who correspond to skills[0] and skills[1]. All the remaining people will form a queue, in the order in which they are given in skills. After each game the following things will happen, in order:
  1. The person who lost the game leaves the table and goes to the end of the queue.
  2. If the person who won the game has already won N games in a row, they also leave the table and they go to the end of the queue (behind the person who lost the last game).
  3. While there are fewer than two people at the table, the first person in the queue leaves the queue and goes to the table.
  4. The two people at the table play the next game.
You are given the int[] skills, the int N, and an int K. Return the two-element int[] { L, W }, where L and W are the skills of the loser and the winner of game K, in this order.

Constraints

  • skills will contain between 2 and 50 elements, inclusive.
  • Each element of skills will be between 1 and 50, inclusive.
  • All elements of skills will be distinct.
  • N will be between 1 and 100, inclusive.
  • K will be between 1 and 1000, inclusive.
Examples
0)
{1, 2, 3}
2
2
Returns: {2, 3 }

In all annotations, we call people by their skill. For example, "player 7" means "the player whose skill level is 7". In this example players 1 and 2 play the first game, and player 2 wins. For the second game, player 3 joins player 2, so we return { 2, 3 }.

1)
{1, 2, 3}
2
4
Returns: {1, 2 }

The sequence of games is as follows: Player 1 loses to player 2. Player 2 loses to player 3. Player 1 loses to player 3. After this player 1 joins the queue, player 3 also steps down because he just won 2 games in a row and joins the queue. Player 1 loses to player 2.

2)
{50, 1}
1
1
Returns: {1, 50 }
3)
{8, 12}
1
1000
Returns: {8, 12 }
4)
{31, 29}
100
1
Returns: {29, 31 }

Submissions are judged against all 70 archived test cases, of which 5 are shown here. Case numbers match the judge’s.

Coding Area

Language: C++17 · define a public class PingPongQueue with a public method vector<int> whoPlaysNext(vector<int> skills, int N, int K) · 70 test cases · 2 s / 256 MB per case

Submitting as anonymous