SRM 152 1A 2013.12.5
DIV1
250
Problem Statement
You and your friends are setting up afantasy TopCoder league, where you choose coders to be on your team and scorepoints in the league when any one of your coders wins their room orsuccessfully challenges somebody, etc. To be fair, a system has been developedto 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 thefirst position gets first pick, the second player gets second pick, all the wayuntil the last player picks. Then the order reverses: the last player choosesagain, then the next to last player, and so on, until you reach the firstplayer again. Then the cycle repeats: the first position chooses again, thenthe second, and so on.
For example: say you were in the thirdposition on a 6 player league. You would get the 3rd pick, then you'd waituntil the 10th pick (the order would be 1,2,you,4,5,6,6,5,4,you), and then the15th pick, and so on until there were no more coders to choose. If there were20 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 inthe order that you have them. You will receive three ints indicating yourposition in the league(1 being the first position), the number of friends thatare in the league with you, and the number of picks that are being divvied upamong the league. You will return an vector <int> that indicates thepicks that you receive in ascending order.
Definition
Class:
LeaguePicks
Method:
returnPicks
Parameters:
int, int, int
Returns:
vector <int>
Method signature:
vector <int> returnPicks(intposition, int friends, int picks)
(be sure your method is public)
Notes
-
Note that your position in the league andthe pick numbers start at 1 and not 0. This should be clear from the examples.
Constraints
-
position will be between 1 and friendsinclusive.
-
friends will be between 1 and 40 inclusive.
-
picks will be between 1 and 40 * friendsinclusive.
Examples
0)
3
6
15
Returns: { 3, 10, 15}
Example from above.
1)
1
1
10
Returns: { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 }
You're the only player, so you get all thepicks.
2)
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 everyset of 4.
3)
5
11
100
Returns: { 5, 18, 27, 40, 49, 62, 71, 84, 93}
You'll get the 5th and (2*11-5+1) or 18thpicks out of every 2*11 picks.
This problem statement is the exclusive andproprietary property of TopCoder, Inc. Any unauthorized use or reproduction ofthis information without the prior written consent of TopCoder, Inc. isstrictly prohibited. (c)2003, TopCoder, Inc. All rights reserved.
173.51
#include<vector>
#include<iostream>
using namespace std;
class LeaguePicks
{
public:vector <int> returnPicks(intposition, int friends, int picks)
{
vector<int> ans;
ans.clear();
int p1=position,p2=2*friends+1-position;
int round= picks/friends/2;
for(int i=1;i<=round;i++)
{
ans.push_back(p1);
ans.push_back(p2);
p1+=2*friends;
p2+=2*friends;
}
p2-=2*friends;
int rest=picks % (friends*2);
if (rest==0) return ans;
if (rest<=friends+friends-position)
{
ans.push_back(position+p2-1+position);
}
else
{
ans.push_back(position+p2-1+position);
ans.push_back(position+p2-1+friends+friends-position+1);
}
return ans;
}
};