TopCoder Topics and my procedures (3)--league picks

Source: Internet
Author: User
Tags printf

A topcoder topic, relatively simple

==============================================================

You and your friends is setting up a fantasy TopCoder league, where the Choose coders to is on your team and score points In the league if any one of your coders wins their or successfully challenges somebody, etc. To is fair, a system has been developed to choose the order in which picks is distributed. It works like This:first, lots is 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 the-the-the-until the last PL Ayer 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 your were in the third position on a 6 player league. You would get the 3rd pick when you ' d wait until the 10th pick (the order would is 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 total picks and then you would get pick numbers 3,10,15.

Not wanting to miss your chance at a pick, your goal are to write a program this tells what do pick numbers you had in th E order that you have them. You'll receive three ints indicating your position in the league (1 being the first position) and the number of friends that is in the league with your, and the number of picks that is being divvied up among the league. You'll return an int[] that indicates the picks so you receive in ascending order.

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 was public)
????

Notes
-note that your position in the league and the pick numbers start at 1 and not 0. This should is clear from the examples. Constraints
-position'll be between 1 and friends inclusive.
-friends'll be between 1 and inclusive.
-picks'll be between 1 and friends * inclusive.

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 and so get all the picks.
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 every set 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 18th picks out of every 2*11 picks.

This problem statement are the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly p Rohibited. (c) 2003, TopCoder, Inc. All rights reserved.
==============================================================

The source program is as follows #include < stdio.h >
#include < vectors >

#define MAXPICKS 40

using namespace Std;

Class Leaguepicks
... {
Public
int m_position; Your position
int m_friends; The number of all friends
int m_picks; The number of all picks

Vector <int> M_vecpicknumbers;

Public
Leaguepicks ();
~leaguepicks ();

It can also return the type of "vector<int>"
void returnpicks (int position,int friends,int picks);

void display ();
} ;

Leaguepicks::leaguepicks ()
... {
}

Leaguepicks:: ~ leaguepicks ()
... {
}

void leaguepicks::returnpicks (int position, int friends, int picks)
... {
int i=0,j=0,s=0;
int Pick1,pick2;

M_vecpicknumbers.clear ();
while (1)
... {
Pick1=s+position;
pick2=s+2*friends-position+1;

if (pick1>picks)
Break
M_vecpicknumbers.push_back (PICK1);

if (pick2>picks)
Break
M_vecpicknumbers.push_back (PICK2);

S+=2*friends;
}
}

Display your pick numbers
void Leaguepicks::d isplay ()
... {
for (int i=0;i<m_vecpicknumbers.size (); i++)
printf ("%3d", m_vecpicknumbers.at (i));
printf ("");
}

void Main ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.