#1: 作者: voice, 时间: 2008-11-07 12:52
请先把题抄下来, 半小时之后我会删掉。
#2: 作者: webdriver, 时间: 2008-11-07 12:55
gettext 写道:
请先把题抄下来, 半小时之后我会删掉。
问题说明
你需要对一组学生(男女生都有),进行从高到低排队,同时要求男女生间隔着。
输入:你将得到用一个数组(vector<string>存储的学生信息,每个学生信息为“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"
外? 这下你删不掉了啵
#3: 作者: myversa, 时间: 2008-11-07 12:56
lazy to read all the problem statement...
#4: 作者: voice, 时间: 2008-11-07 13:04
webdriver 写道:
外?
这下你删不掉了啵
太好了, 这是topcoder上的题, 因为版权上的问题, 这是你贴的啊。
#5: 作者: SARS, 时间: 2008-11-07 13:08
怎么这么快就删掉?太不厚道
不错的题目
但有个问题:是不是男女孩要严格错开——像“男女男女......”这样?看起来很容易无解。
#6: 作者: 许万克, 时间: 2008-11-07 13:15
gettext 写道:
webdriver 写道:
外?
这下你删不掉了啵
太好了, 这是topcoder上的题, 因为版权上的问题, 这是你贴的啊。
Ha, gettext , you're bad,
#7: 作者: SARS, 时间: 2008-11-07 13:18
俺的思路:用桶式排序
1、建150个坑(桶),分别给100cm~250cm高度的。
2、扫描学生列表,按高度入坑
3、对有孩子的坑做简单的交换移位,错开男女
4、从低到高把桶里的孩子倒出来
学习委员,这样行不行?有没有时间、空间方面更多的限制?
#8: 作者: webdriver, 时间: 2008-11-07 13:22
gettext 写道:
webdriver 写道:
外?
这下你删不掉了啵
太好了, 这是topcoder上的题, 因为版权上的问题, 这是你贴的啊。
俺考虑用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、然后再解。。。(对不起,没时间想了现在)
output generated using printer-friendly topic mod, 所有的时间均为 美国太平洋时间