由买买提看人间百态

boards

本页内容为未名空间相应帖子的节选和存档,一周内的贴子最多显示50字,超过一周显示500字 访问原贴
JobHunting版 - 网上一道A家面试题
相关主题
一道JAVA 设计面试题请教一下怎么评价你的former supervisor
请教回答这几道面试题(针对文科),谢谢。请教behavior question
Public Health PhD 业界求职经验3-面试Urgent! Interview 棒球统计问题求助
General Interview Questions一个recruiter给我发的职位,我不行了,转发给大家。别给我发
怀孕7个月面试总结how to state your strength and weakness?
攒rp:opt有gap的cover方法及其他,大家补充interview 归来 - 求祝福
被炒了,找工作的时候HR问起来该怎么回答?今年就业形势是比往年差吧
这两个问题有什么区别?自己总结的面试必准备的问题
相关话题的讨论汇总
话题: athletes话题: strength话题: number话题: input话题: masses
进入JobHunting版参与讨论
1 (共1页)
M**A
发帖数: 78
1
Every athlete is characterized by his mass 'm' (in kg) and strength 's' (in
kg). You are to find the maximum number of athletes that can form a tower
standing one upon another. An athlete can hold a tower of athletes with
total mass equal to his strength or less than his strength. Input contains
the number of athletes n and their parameters. These inputs can be assumed
to be passed as arguments (Integer n and List> parameterList) appropriate
for your language of choice: For example:
n m1 s1 m2 s2 ... mn sn If mi > mj then si > sj, but athletes with equal
masses can be of different strength. Number of athletes n < 100000. Masses
and strengths are positive integers less than 2000000.
For example: Input #1: 4 3 4 2 2 7 6 4 5
Would yield Output #1: 3
https://github.com/fabiensanglard/Pyramid
搭人梯 7 6 = 3 4 + 2 2 或者 2 2 + 4 5 共3个人
除了brute force, 各位朋友有何高见?
f*****e
发帖数: 2992
2
Greedy吧,
先找重量最轻的,记为m1
然后找min(m_i) where si>m1
然后找min(m_i) where si>m1 + m2
然后找min(m_i) where si>m1 + m2 + m3

in

【在 M**A 的大作中提到】
: Every athlete is characterized by his mass 'm' (in kg) and strength 's' (in
: kg). You are to find the maximum number of athletes that can form a tower
: standing one upon another. An athlete can hold a tower of athletes with
: total mass equal to his strength or less than his strength. Input contains
: the number of athletes n and their parameters. These inputs can be assumed
: to be passed as arguments (Integer n and List> parameterList) appropriate
: for your language of choice: For example:
: n m1 s1 m2 s2 ... mn sn If mi > mj then si > sj, but athletes with equal
: masses can be of different strength. Number of athletes n < 100000. Masses
: and strengths are positive integers less than 2000000.

c**s
发帖数: 159
3
dp...按m排序 背包之
l***i
发帖数: 1309
4
why not sort by strength?
p*****2
发帖数: 21240
5
sort by m and s then dp

【在 M**A 的大作中提到】
: Every athlete is characterized by his mass 'm' (in kg) and strength 's' (in
: kg). You are to find the maximum number of athletes that can form a tower
: standing one upon another. An athlete can hold a tower of athletes with
: total mass equal to his strength or less than his strength. Input contains
: the number of athletes n and their parameters. These inputs can be assumed
: to be passed as arguments (Integer n and List> parameterList) appropriate
: for your language of choice: For example:
: n m1 s1 m2 s2 ... mn sn If mi > mj then si > sj, but athletes with equal
: masses can be of different strength. Number of athletes n < 100000. Masses
: and strengths are positive integers less than 2000000.

F********9
发帖数: 44
6
LZ这是招人做家庭作业的吧。
我之前申A时,这道题是家庭作业,做完发给recruiter的。
on site 时,有个面试官想出这道题,我直接说,这是A的家庭作业, 给否了。
祝你好运。
p*****2
发帖数: 21240
7

这题有OJ吗?

【在 F********9 的大作中提到】
: LZ这是招人做家庭作业的吧。
: 我之前申A时,这道题是家庭作业,做完发给recruiter的。
: on site 时,有个面试官想出这道题,我直接说,这是A的家庭作业, 给否了。
: 祝你好运。

t****a
发帖数: 1212
8
确定么?这个例子
m s
1 6
2 3
3 0
如果按照m从小到大排序后dp结果是((1 6) (2 3))
从大到小排序后dp结果是 ((3 0) (2 3) (1 6))

【在 p*****2 的大作中提到】
: sort by m and s then dp
p*****2
发帖数: 21240
9

你miss了一个重要条件。
这题有点greedy+dp的意思。呵呵。

【在 t****a 的大作中提到】
: 确定么?这个例子
: m s
: 1 6
: 2 3
: 3 0
: 如果按照m从小到大排序后dp结果是((1 6) (2 3))
: 从大到小排序后dp结果是 ((3 0) (2 3) (1 6))

1 (共1页)
进入JobHunting版参与讨论
相关主题
自己总结的面试必准备的问题怀孕7个月面试总结
请问如何在面试中show interest攒rp:opt有gap的cover方法及其他,大家补充
G onsite面经 加求blessing被炒了,找工作的时候HR问起来该怎么回答?
老板要叫我们写360 reivew, 求几个例句这两个问题有什么区别?
一道JAVA 设计面试题请教一下怎么评价你的former supervisor
请教回答这几道面试题(针对文科),谢谢。请教behavior question
Public Health PhD 业界求职经验3-面试Urgent! Interview 棒球统计问题求助
General Interview Questions一个recruiter给我发的职位,我不行了,转发给大家。别给我发
相关话题的讨论汇总
话题: athletes话题: strength话题: number话题: input话题: masses