Problem Statement
You and your friends are setting up a fantasy TopCoder league, where you choose coders to be on your team and score points in the league when any one of your coders wins their room or successfully challenges somebody, etc. To be fair, a system has been developed to choose the order in which picks are distributed. It works like this: first, lots are drawn to choose your position in the league. Then the player with the first position gets first pick, the second player gets second pick, all the way until the last player picks. Then the order reverses: the last player chooses again, then the next to last player, and so on, until you reach the first player again. Then the cycle repeats: the first position chooses again, then the second, and so on.
For example: say you were in the third position on a 6 player league. You would get the 3rd pick, then you'd wait until the 10th pick (the order would be 1,2,you,4,5,6,6,5,4,you), and then the 15th pick, and so on until there were no more coders to choose. If there were 20 total picks, then you would get pick numbers 3,10,15.
Not wanting to miss your chance at a pick, your goal is to write a program that tells you what pick numbers you have in the order that you have them. You will receive three
Definition
- Class:
- LeaguePicks
- Method:
- returnPicks
- Parameters:
- int, int, int
- Returns:
- int[]
- Method signature:
- int[] returnPicks(int position, int friends, int picks)
- (be sure your method is public)
Notes
- Note that your position in the league and the pick numbers start at 1 and not 0. This should be clear from the examples.
Constraints
- position will be between 1 and friends inclusive.
- friends will be between 1 and 40 inclusive.
- picks will be between 1 and 40 * friends inclusive.
Examples
3
6
15
Returns: { 3, 10, 15 }
Example from above.
1
1
10
Returns: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
You're the only player, so you get all the picks.
1
2
39
Returns: { 1, 4, 5, 8, 9, 12, 13, 16, 17, 20, 21, 24, 25, 28, 29, 32, 33, 36, 37 }
You'll get the 1st and 4th picks in every set of 4.
5
11
100
Returns: { 5, 18, 27, 40, 49, 62, 71, 84, 93 }
You'll get the 5th and (2*11-5+1) or 18th picks out of every 2*11 picks.
17
40
1600
Returns: { 17, 64, 97, 144, 177, 224, 257, 304, 337, 384, 417, 464, 497, 544, 577, 624, 657, 704, 737, 784, 817, 864, 897, 944, 977, 1024, 1057, 1104, 1137, 1184, 1217, 1264, 1297, 1344, 1377, 1424, 1457, 1504, 1537, 1584 }
3
4
100
Returns: { 3, 6, 11, 14, 19, 22, 27, 30, 35, 38, 43, 46, 51, 54, 59, 62, 67, 70, 75, 78, 83, 86, 91, 94, 99 }
2
4
100
Returns: { 2, 7, 10, 15, 18, 23, 26, 31, 34, 39, 42, 47, 50, 55, 58, 63, 66, 71, 74, 79, 82, 87, 90, 95, 98 }
1
4
100
Returns: { 1, 8, 9, 16, 17, 24, 25, 32, 33, 40, 41, 48, 49, 56, 57, 64, 65, 72, 73, 80, 81, 88, 89, 96, 97 }
4
4
100
Returns: { 4, 5, 12, 13, 20, 21, 28, 29, 36, 37, 44, 45, 52, 53, 60, 61, 68, 69, 76, 77, 84, 85, 92, 93, 100 }
1
1
20
Returns: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 }
You're the only person in your league, and thus you get all the picks.
1
1
1
Returns: { 1 }
2
2
4
Returns: { 2, 3 }
3
5
20
Returns: { 3, 8, 13, 18 }
17
40
1600
Returns: { 17, 64, 97, 144, 177, 224, 257, 304, 337, 384, 417, 464, 497, 544, 577, 624, 657, 704, 737, 784, 817, 864, 897, 944, 977, 1024, 1057, 1104, 1137, 1184, 1217, 1264, 1297, 1344, 1377, 1424, 1457, 1504, 1537, 1584 }
9
30
1024
Returns: { 9, 52, 69, 112, 129, 172, 189, 232, 249, 292, 309, 352, 369, 412, 429, 472, 489, 532, 549, 592, 609, 652, 669, 712, 729, 772, 789, 832, 849, 892, 909, 952, 969, 1012 }
15
17
23
Returns: { 15, 20 }
39
40
42
Returns: { 39, 42 }
7
9
11
Returns: { 7 }
5
10
45
Returns: { 5, 16, 25, 36, 45 }
18
37
979
Returns: { 18, 57, 92, 131, 166, 205, 240, 279, 314, 353, 388, 427, 462, 501, 536, 575, 610, 649, 684, 723, 758, 797, 832, 871, 906, 945 }
6
6
35
Returns: { 6, 7, 18, 19, 30, 31 }
5
10
1
Returns: { }
4
5
9
Returns: { 4, 7 }
40
40
1600
Returns: { 40, 41, 120, 121, 200, 201, 280, 281, 360, 361, 440, 441, 520, 521, 600, 601, 680, 681, 760, 761, 840, 841, 920, 921, 1000, 1001, 1080, 1081, 1160, 1161, 1240, 1241, 1320, 1321, 1400, 1401, 1480, 1481, 1560, 1561 }