coding test 第一题。 (高手莫入)
分页: 1, 2, 3, 4  下一页    :| |:
移民生活北美论坛 -> IT人生

#1: 作者: voice时间: 2008-11-07 12:52

请先把题抄下来, 半小时之后我会删掉。 icon_smile.gif

#2: 作者: webdriver时间: 2008-11-07 12:55

gettext 写道:
请先把题抄下来, 半小时之后我会删掉。 icon_smile.gif


问题说明
    
你需要对一组学生(男女生都有),进行从高到低排队,同时要求男女生间隔着。

输入:你将得到用一个数组(vector<string>icon_wink.gif存储的学生信息,每个学生信息为“name height sex”,height是一个整数,单位cm; sex为性别,可以为 "boy" 或者 "girl" 之一。
返回:返回一个字符串,包含用“-”连接起来的排序后的每个学生的名字。如果存在多个可能结果,则选择按照字母顺序最优的解。如果无解,返回空串。
    
Class:
StudentsOrdering
Method:
findOrder
Parameters:
vector <string>
Returns:
string
Method signature:
string findOrder(vector <string> students)
(be sure your method is public)
    

Constraints
-
students will contain between 1 and 50 elements, inclusive.
-
Each element of students will be contain between 1 and 50 characters, inclusive.
-
Each element of students will be formatted as described in the problem statement.
-
The name of each student will consist of letters ('A'-'Z', 'a'-'z') only.
-
The height of each student will be between 100 and 250, inclusive.
-
The height of each student will contain no leading zeroes.
Examples
0)

    
{"Alex 180 boy",
"Josh 181 boy",
"Mary 158 girl",
"An 158 girl",
"Tanya 180 girl",
"Ted 158 boy"}
Returns: "An-Ted-Mary-Alex-Tanya-Josh"

1)

    
{"Alex 180 boy",
"Josh 158 boy",
"Mary 180 girl",
"An 158 girl",
"Mary 180 girl",
"Ted 158 boy"}
Returns: "Josh-An-Ted-Mary-Alex-Mary"
Student names can repeat.
2)

    
{"Alex 180 boy",
"Josh 170 boy",
"An 158 girl",
"Mary 180 girl",
"Ted 175 boy"}
Returns: ""
There is no girl to place between Josh and Ted.
3)

    
{"Mary 175 girl"}
Returns: "Mary"


外? big_happy.gif 这下你删不掉了啵 big_happy.gif

#3: 作者: myversa时间: 2008-11-07 12:56

lazy to read all the problem statement...

#4: 作者: voice时间: 2008-11-07 13:04

webdriver 写道:
外? big_happy.gif 这下你删不掉了啵 big_happy.gif


太好了, 这是topcoder上的题, 因为版权上的问题, 这是你贴的啊。icon_smile.gif

#5: 作者: SARS时间: 2008-11-07 13:08

怎么这么快就删掉?太不厚道 big_mad.gif

不错的题目 yc_85.gif

但有个问题:是不是男女孩要严格错开——像“男女男女......”这样?看起来很容易无解。

#6: 作者: 许万克时间: 2008-11-07 13:15

gettext 写道:
webdriver 写道:
外? big_happy.gif 这下你删不掉了啵 big_happy.gif


太好了, 这是topcoder上的题, 因为版权上的问题, 这是你贴的啊。icon_smile.gif


Ha, gettext , you're bad, big_happy.gif

#7: 作者: SARS时间: 2008-11-07 13:18

俺的思路:用桶式排序

1、建150个坑(桶),分别给100cm~250cm高度的。
2、扫描学生列表,按高度入坑
3、对有孩子的坑做简单的交换移位,错开男女
4、从低到高把桶里的孩子倒出来

学习委员,这样行不行?有没有时间、空间方面更多的限制?

#8: 作者: webdriver时间: 2008-11-07 13:22

gettext 写道:
webdriver 写道:
外? big_happy.gif 这下你删不掉了啵 big_happy.gif


太好了, 这是topcoder上的题, 因为版权上的问题, 这是你贴的啊。icon_smile.gif


俺考虑用google translate一下,估计就没版权问题袅

#9: 作者: voice时间: 2008-11-07 13:44

SARS 写道:
俺的思路:用桶式排序

1、建150个坑(桶),分别给100cm~250cm高度的。
2、扫描学生列表,按高度入坑
3、对有孩子的坑做简单的交换移位,错开男女
4、从低到高把桶里的孩子倒出来

学习委员,这样行不行?有没有时间、空间方面更多的限制?


对, 这样也可以, 但我想每个坑里把男女分开可能会好些。

#10: 作者: webdriver时间: 2008-11-07 13:54

1、先判断一下男女生人数是否有解 - 男女生人数得相差1或相等

2、然后再解。。。(对不起,没时间想了现在) 




移民生活北美论坛 -> IT人生


output generated using printer-friendly topic mod, 所有的时间均为 美国太平洋时间

分页: 1, 2, 3, 4  下一页    :| |:
1页,共4

Powered by phpBB 2.0.8
Content received from: 加西网 (温哥华门户), https://www.westca.com