×

# ONCHESS - Editorial

Tester: Amr Mahmoud
Editorialist: Bhuvnesh Jain

EASY

# Prerequisites

Looping Techniques

# Problem

Find a suitable match for every person depending on some constraints mentioned in the statement.

# Explanation

The solution is simply doing what the problem statement says. Just maintain a "wait" variable for all players, which when set to $1$ means that the player is still waiting for his chance to pair up with someone, and $0$ meaning that the person is already paired up.

Thus, for every player, we start from the first person and proceed in increasing order of their times of arrival and break as soon as we get some matching person whose "wait" variable was set to "1".

To check if any person matches with someone else, we can simply use "if" statements to check the conditions mentioned in the statement.

1. The first condition can be checked as follows : $y <= x \\text{ and } x <= z$, meaning that $x$ lies in the range $[y, z]$
2. The second and third condition can be simply checked by comparing the 2 values i.e. time and "rated/unrated" criteria.
3. For last condition, we first check to which category it belongs i.e. $\\{ \\text{random, black, white} \\}$. Then as per the category, we do the corresponding check for the other player i.e. "random" matches with "random", "black" with "white" and "white" with "black".

# Time Complexity

$O(N^2)$, per test case.

# Space Complexity

$O(N)$

This question is marked "community wiki".

6★likecs
3.7k2481
accept rate: 9%

19.8k350498541

 0 This question is easy . just as the players are entered one by one let say if we want to check for the k th player. you have to see always through the 1 player till k using loop(lets assume loop counter to be i) . and for every cycle check that the i th player is not entered in any of the game(by creating an bool var and setting true or false >>> if the bool var is false that means the player is still waiting) and also the i th player should satisfy the parameters for the kth player and kth player too should satisfy the parameters for the ith player as mentioned in the ques .(means check that the R i must in between [MINk,MAXk] and the Rk in between of [MINi,MAXi]. And if the loop fully completes till k and no such player is found just ask the k th player to wait . Rem for checking that the player satisfy each other parameters or not you have to maintain a structure with all the fields given in ques and when corresponding to any player other player has been matched then both bool variables should be setted as TRUE Indicating that they are not the part of process any more and can be skipped in the previous for loop iterations only by checking that their bool variables are true that means the player is paired with some other player.. My solution:: P.S Bad Formatting My Solution answered 28 Nov '17, 16:30 21●4 accept rate: 0%
 toggle preview community wiki:
Preview

By Email:

Markdown Basics

• *italic* or _italic_
• **bold** or __bold__
• image?![alt text](/path/img.jpg "title")
• numbered list: 1. Foo 2. Bar
• to add a line break simply add two spaces to where you would like the new line to be.
• basic HTML tags are also supported
• mathemetical formulas in Latex between \$ symbol

Question tags:

×15,852
×3,820
×593
×191
×102
×98
×28

question asked: 19 Nov '17, 21:30

question was seen: 578 times

last updated: 28 Nov '17, 16:30