一亩三分地

 找回密码 注册账号

扫描二维码登录本站

BBS
Offer多多
Salarytics
交友
Learn
Who's Hiring?
Visa Tracker
疫情动态
指尖新闻
Instant
客户端
微信公众号
扫码关注公众号
留学申请公众号
扫码关注留学申请公众号
Youtube频道
留学博客
关于我们
查看: 276|回复: 1
收起左侧

[高频题] OA 遇到的一道题 请大佬帮忙看看

[复制链接] |只看干货 |高频题, 刷题
我的人缘0

升级   71%


分享帖子到朋友圈
本楼: 👍   0% (0)
 
 
0% (0)   👎
全局: 👍   100% (4)
 
 
0% (0)    👎

注册一亩三分地论坛,查看更多干货!

您需要 登录 才可以下载或查看,没有帐号?注册账号

x
我是先从小到大排序 然后双指针把最大的拿出来从大到小加在一起 保证每次能拿的最满
时间复杂度n^2  感觉自己的做法效率太差了  请大佬看看想下更好的解法

The janitor at Hacker High School is insanely efficient. By the end of
each day, all of the waste from the trash cans in the school has been
shifted into plastic bags which can carry waste weighing between 1.01
pounds and 3.00 pounds. All of the plastic bags must be dumped into
the trash cans outside the school. The janitor can carry at most 3.00
pounds at once. One trip is described as selecting a few bags which
together don't weigh more than 3.00 pounds, dumping them in the
outdoor trash can and returning to the school. The janitor wants to
make minimum number of trips to the outdoor trash can. Given the
number of plastic bags, n, and the weights of each bag, determine the
minimum number of trips if the janitor selects bags in the optimal way.
For example, given n = 6 plastic bags weighing weight = [1.01, 1.99, 2.5,
1.5, 1.01], the janitor can carry all of the trash out in 3 trips: [1.01 +
1.99 , 2.5, 1.5 + 1.01].
Function Description
Complete the function efficientJanitor in the editor below. The
function must return a single integer that represents the minimum
number of trips to be made.
efficientJanitor has the following parameter(s):
weight[weight[0],...weight[n-1]]: an array of floating-point integers
Constraints
1 ≤ n ≤ 1000
1.01 ≤ weight[i] ≤ 3.0

评分

参与人数 1大米 +8 收起 理由
14417335 + 8

查看全部评分


上一篇:请教大家一个LRU实现的问题
下一篇:353 Design snake game 总是过不了
我的人缘0

升级   25.86%

mc2 2020-9-21 23:54:46 | 显示全部楼层
本楼: 👍   0% (0)
 
 
0% (0)   👎
全局: 👍   99% (162)
 
 
0% (1)    👎
利口巴巴腰
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号

本版积分规则

隐私提醒:
■拉群请前往同学同事飞友|拉群结伴版块,其他版块拉群,帖子会被自动删除
■论坛不能删帖,为防止被骚扰甚至人肉,不要公开留微信等联系方式,请以论坛私信方式发送。
■特定版块可以超级匿名:https://pay.1point3acres.com/tools/thread
■其他版块匿名方法:http://www.1point3acres.com/bbs/thread-405991-1-1.html

手机版|||一亩三分地

Powered by Discuz! X3

© 2001-2013 Comsenz Inc. Design By HUXTeam

Some icons made by Freepik from flaticon.com

快速回复 返回顶部 返回列表