回复: 9
跳转到指定楼层
上一主题 下一主题
收起左侧

狗家跪经

全局:

2017(10-12月) 码农类General 硕士 全职@google - 内推 - Onsite  | | Other | 在职跳槽

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

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

x
问了一个shuffle array with weight,
您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
使用VIP即刻解锁阅读权限或查看其他获取积分的方式
游客,您好!
本帖隐藏的内容需要积分高于 188 才可浏览
您当前积分为 0。
VIP即刻解锁阅读权限查看其他获取积分的方式
Unlock interview details and practice with AI
Curated Interview Questions from Top Companies
th weight的最优解法吗?

上一篇:林银电面第一轮
下一篇:Google加面什么难度?求经验。。
推荐
roosterxie 2017-12-5 13:19:40 | 只看该作者
全局:
https://stackoverflow.com/questions/23971365/weighted-randomized-ordering

  1. You have items with weights:

  2. Item A, weight 42
  3. Item B, weight 5
  4. Item C, weight 96
  5. Item D, weight 33
  6. First add up all the weights: 42 + 5 + 96 + 33 = 176

  7. Now pick a random number, r, from 0 up to the sum of the weights: 0 <= r < 176. I have used integers, but you could use reals if required.

  8. Compare r with the ranges defined by the weights:

  9. 0 <= r < 42: select item A.
  10. 42 <= r < 47 (= 42 + 5): select item B.
  11. 47 <= r < 143 (= 47 + 96): select item C.
  12. 143 <= r < 176 (= 143 + 33): select item D.
  13. When you have picked the first item, then repeat the process with the three remaining items and a reduced sum of all the weights. Keep repeating until there are no more items to pick.
复制代码

这个应该是最简单的方法了
回复

使用道具 举报

🔗
hychin 2017-12-5 08:10:44 | 只看该作者
全局:
啥叫shuff array with weight? 解释下?
回复

使用道具 举报

🔗
672347250 2017-12-5 09:24:10 | 只看该作者
本楼:
全局:
就一轮么?
回复

使用道具 举报

🔗
hychin 2017-12-14 10:24:58 | 只看该作者
全局:
roosterxie 发表于 2017-12-5 13:19
https://stackoverflow.com/questions/23971365/weighted-randomized-ordering

这个应该是最简单的方法 ...

你这个办法是O(n^2),我研究了下,这个题用二叉树可以做到nlogn
回复

使用道具 举报

🔗
littlegrass 2017-12-30 05:16:40 | 只看该作者
全局:
hychin 发表于 2017-12-14 10:24
你这个办法是O(n^2),我研究了下,这个题用二叉树可以做到nlogn

请问下 如何用二叉树可以做到nlogn
回复

使用道具 举报

🔗
kaixinNI 2017-12-31 13:36:21 | 只看该作者
全局:
littlegrass 发表于 2017-12-30 05:16
请问下 如何用二叉树可以做到nlogn

你好,想请问怎么用二叉树做到nlogn呢? 谢谢!
回复

使用道具 举报

🔗
kaixinNI 2017-12-31 13:37:29 | 只看该作者
全局:
hychin 发表于 2017-12-14 10:24
你这个办法是O(n^2),我研究了下,这个题用二叉树可以做到nlogn

你好,想请问怎么用二叉树做到nlogn呢? 谢谢! 刚才不小心回复错了
回复

使用道具 举报

🔗
IsingModel 2017-12-31 16:20:09 | 只看该作者
全局:
https://www.quora.com/Is-there-a-simple-O-nlogn-algorithm-for-Weighted-Shuffling-of-cards
可以nlogn 但是得自己建树  写起来应该比较麻烦吧
回复

使用道具 举报

全局:
几号面的呀?
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

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