avatar
网上一道A家面试题# JobHunting - 待字闺中
M*A
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, 各位朋友有何高见?
avatar
f*e
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.

avatar
c*s
3
dp...按m排序 背包之
avatar
l*i
4
why not sort by strength?
avatar
p*2
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.

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

这题有OJ吗?

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

avatar
t*a
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
avatar
p*2
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))

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。