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 ints indicating your position in the league(1 being the first position), the number of friends that are in the league with you, and the number of picks that are being divvied up among the league. You will return an int[] that indicates the picks that 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 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
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 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 is 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 prohibited. (c)2003, TopCoder, Inc. All rights reserved.
我的算法
java 代码
- public class LeaguePicks {
- public int[] returnPicks(int position, int friends, int picks) {
- int count;
- int Acount;
- int Pcount = picks / friends;
-
- Acount = (Pcount % 2 == 0 && position <= picks % friends) || (Pcount % 2 == 1 && friends - position + 1 <= picks % friends) ? Pcount + 1 : Pcount;
- int out[] = new int[Acount];
-
-
- for (int i = 0; i < Acount; i++) {
-
- out[i] = i * friends + position + i % 2 * (friends - 2 * position + 1);
-
-
- }
-
- return out;
分享到:
相关推荐
【标签】"topcoder"暗示了这个压缩包可能包含一系列与Topcoder平台相关的学习材料,比如历年的比赛题目、解题思路、算法教程、编程实践案例,甚至可能是社区成员分享的笔记和经验总结。 【压缩包子文件的文件名称...
Topcoder SRM 499 的第一题是一道简单的 Addition Game 题目,旨在考察程序员对问题的理解和算法设计能力。本文将详细讲解该题目的知识点和解题思路。 题目分析 该题目中,Fox Ciel 在游戏 Addition Game 中通过...
TopCoder还提供了丰富的学习资源,如讨论区、教程和过去的竞赛题目,帮助你提升编程技能。 8. **积分系统** 在TopCoder,你的表现将被转化为积分,包括算法、设计和开发积分。积分反映了你在不同领域的竞争力,也...
算法竞赛和高中组竞赛都使用TopCoder开发的专用竞赛软件Arena进行,这是一个Java应用程序,要求参赛者的计算机上安装有Java运行环境(JRE) 1.4或更高版本。在Arena的登录界面,新用户可以找到注册入口,注册时至少...
1. "point-500.txt":这个名字可能暗示了一个比赛题目,其中“point-500”可能代表该问题在TopCoder平台上可能的分数。在TopCoder的马拉松匹配(Marathon Match)中,问题难度和分数通常会根据解决难度进行划分。这...
2. **单轮比赛(SRM)**:SRM是Topcoder的主要比赛形式,每场比赛包含三道不同难度的算法题,参赛者需要在规定时间内完成尽可能多的题目。 3. **用户ID**:在Topcoder上,每个参赛者都有一个独特的ID,即“手柄”,如...
2. **算法和数据结构**:TopCoder 上的题目涵盖了各种算法和数据结构,如排序、搜索、图论、动态规划、回溯、贪心策略等。Python 解决方案将体现这些算法的应用。 3. **Python 库的使用**:项目可能使用了一些 ...
- 所有参赛者都可以在TopCoder的Design部分选择题目。 - 选手积分由排名分乘以题目奖金计算,排名分等于11减去选手名次。 - 参赛流程包括在TopCoder官网注册、在软件设计比赛中国赛网页注册参赛。 - 奖励包括...
4. **数学知识**:许多TopCoder题目涉及到离散数学、组合数学、数论等领域的知识,如排列组合、数列、模运算、数学归纳法等。 5. **复杂度分析**:理解并能够进行时间复杂度和空间复杂度分析,这是评估算法效率的...
在TopCoder上,参赛者可以参与到算法比赛、软件开发项目中,提升编程技能并赚取报酬。这里的“插件”可能是指用于增强TopCoder平台功能或提升开发者体验的第三方工具。 “CodeProcessor”很可能是一个代码处理工具...
根据提供的标题“编程竞赛实例算法完整版”及描述“编程竞赛算法经典入门,算法实例,算法参考”,我们可以归纳总结出以下关键知识点: ### 一、编程竞赛基础 #### 1.1 编程竞赛简介 - **定义**:编程竞赛是一种以...
### 常见算法介绍及应用 #### 排序算法 **堆排序**是一种高效的排序算法,基于二叉堆数据结构。它分为两种主要类型:最大堆和最小堆。最大堆保证每个父节点的值大于或等于其子节点的值;最小堆则相反。堆排序的...
本资源库包含的是我在Codeforces、TopCoder和UVa等知名在线编程竞赛平台上解决算法问题的解决方案。这些平台是检验和提升算法能力的绝佳场所,尤其对于准备ACM/ICPC(国际大学生程序设计竞赛)的选手来说,它们提供...
TopCoder是一个著名的计算机编程竞赛平台,通过提供各种难度的算法和编程问题,供参赛者解决,以测试和提高他们的编程技能。SRM(Single Round Match)是TopCoder上的一种竞赛形式,通常分为不同级别的问题,供参赛...
在编程竞赛领域,TopCoder是一个广为人知的平台,它提供了各种算法挑战,旨在提升参赛者的编程技能,尤其是C++编程能力。TopCoder的问题涵盖了数据结构、算法、数学等多个方面,是程序员锻炼解决问题和逻辑思维的...
在TopCoder上,HTML可能用于实现比赛的前端展示或者作为算法题目的一部分,要求参赛者编写能够正确解析HTML的程序。 从压缩包子文件的文件名称"TopCoder-master"来看,这可能是一个Git仓库的名称,"master"通常是...
此外,课程还提供了TOJ(可能是指Topcoder Online Judge或类似的在线编程竞赛平台)的例题讲解,帮助学习者通过实际操作加深对贪心算法的理解。通过解决这些练习题目,学习者可以锻炼自己的编程能力和问题解决技巧。...
书中涉及的题目和练习通常涵盖基础算法,如排序、搜索、图论、动态规划,以及更高级的主题,如数据结构设计和复杂计算问题的解决。源代码实现提供了直观的解决方案,让读者能够看到如何将理论知识转化为实际的编程...
2. 算法设计:根据题目需求,选择合适的算法和数据结构。Java库中提供了丰富的数据结构和算法实现,如ArrayList、LinkedList、HashMap等,合理运用能提高代码效率。 3. 代码编写:在Java中,代码的可读性和效率同样...
总的来说,2010年中南大学的ACM比赛题目是学习和提升编程技能的宝贵资源,通过对"problem.docx"的深入研究,参赛者不仅可以锻炼编程能力,还能增进对算法和问题解决的理解,为未来的职业生涯奠定坚实基础。