TeamsSelection
SRM 586 · 2013-06-25 · by gojira_tc
Problem Statement
The division into teams works as follows. Initially, the first captain chooses one person for his team. Then, the second captain chooses one boy from those who are left. Then the first captain chooses again, and so on. The process continues until there are no more boys left.
You are given
Return a
Constraints
- preference1 will contain N elements, where N is between 2 and 50, inclusive.
- Elements of preference1 will contain each of the numbers from 1 to N exactly once.
- preference2 will contain N elements.
- Elements of preference2 will contain each of the numbers from 1 to N exactly once.
{1, 2, 3, 4}
{1, 2, 3, 4}
Returns: "1212"
There are 4 boys to be divided between the two captains. Both captains believe that boy 1 plays best, then come boy 2 and boy 3, and boy 4 plays worst. Thus, the first captain will choose boy 1, the second captain will choose boy 2, since boy 1 is already assigned to a team, then the first captain will choose boy 3 and in the end the second captain will take boy 4.
{3, 2, 1}
{1, 3, 2}
Returns: "211"
The first captain will choose boy 3, the second captain will choose boy 1 and then the first captain will choose boy 2. Note that when there is an odd number of children, the first team ends up one man larger.
{6, 1, 5, 2, 3, 4}
{1, 6, 3, 4, 5, 2}
Returns: "212211"
{8, 7, 1, 2, 4, 5, 6, 3, 9}
{7, 2, 4, 8, 1, 5, 9, 6, 3}
Returns: "121121212"
{1,2}
{1,2}
Returns: "12"
Submissions are judged against all 66 archived test cases, of which 5 are shown here. Case numbers match the judge’s.
Language: C++17 · define a public class TeamsSelection with a public method string simulate(vector<int> preference1, vector<int> preference2) · 66 test cases · 2 s / 256 MB per case