Connection Status:
Competition Arena > PeopleCircle
SRM 147 · 2003-05-22 · by axchma · Simulation, String Manipulation
Class Name: PeopleCircle
Return Type: String
Method Name: order
Arg Types: (int, int, int)
Problem Statement

Problem Statement

There are numMales males and numFemales females arranged in a circle. Starting from a given point, you count clockwise and remove the K'th person from the circle (where K=1 is the person at the current point, K=2 is the next person in the clockwise direction, etc...). After removing that person, the next person in the clockwise direction becomes the new starting point. After repeating this procedure numFemales times, there are no females left in the circle.

Given numMales, numFemales and K, your task is to return what the initial arrangement of people in the circle must have been, starting from the starting point and in clockwise order.

For example, if there are 5 males and 3 females and you remove every second person, your return String will be "MFMFMFMM".

Constraints

  • numMales is between 0 and 25 inclusive
  • numFemales is between 0 and 25 inclusive
  • K is between 1 and 1000 inclusive
Examples
0)
5
3
2
Returns: "MFMFMFMM"

Return "MFMFMFMM". On the first round you remove the second person - "M_MFMFMM". Your new circle looks like "MFMFMMM" from your new starting point. Then you remove the second person again etc.

1)
7
3
1
Returns: "FFFMMMMMMM"

Starting from the starting point you remove the first person, then you continue and remove the next first person etc. Clearly, all the females are located at the beginning. Hence return "FFFMMMMMMM"

2)
25
25
1000
Returns: "MMMMMFFFFFFMFMFMMMFFMFFFFFFFFFMMMMMMMFFMFMMMFMFMMF"
3)
4
1
7
Returns: "MFMMM"
4)
3
2
7
Returns: "MFMMF"
11)
5
5
3
Returns: "MFFMMFFMFM"

Here we mark the removed people with '_', and the starting position with lower-case: Number of | People Remaining Rounds | (in initial order) ---------------+----------------- 0 | mFFMMFFMFM 1 | MF_mMFFMFM 2 | MF_MM_fMFM 3 | MF_MM_FM_m 4 | M__mM_FM_M 5 | M__MM__m_M

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

Coding Area

Language: C++17 · define a public class PeopleCircle with a public method string order(int numMales, int numFemales, int K) · 35 test cases · 2 s / 256 MB per case

Submitting as anonymous