沈阳微信网站建设,国外的域名注册网站哪个好,wordpress菜单移动,济南网络seo公司一所学校里有一些班级#xff0c;每个班级里有一些学生#xff0c;现在每个班都会进行一场期末考试。给你一个二维数组 classes #xff0c;其中 classes[i] [passi, totali] #xff0c;表示你提前知道了第 i 个班级总共有 totali 个学生#xff0c;其中只有 passi 个学…一所学校里有一些班级每个班级里有一些学生现在每个班都会进行一场期末考试。给你一个二维数组 classes 其中 classes[i] [passi, totali] 表示你提前知道了第 i 个班级总共有 totali 个学生其中只有 passi 个学生可以通过考试。
给你一个整数 extraStudents 表示额外有 extraStudents 个聪明的学生他们 一定 能通过任何班级的期末考。你需要给这 extraStudents 个学生每人都安排一个班级使得 所有 班级的 平均 通过率 最大 。
一个班级的 通过率 等于这个班级通过考试的学生人数除以这个班级的总人数。平均通过率 是所有班级的通过率之和除以班级数目。
请你返回在安排这 extraStudents 个学生去对应班级后的 最大 平均通过率。与标准答案误差范围在 10-5 以内的结果都会视为正确结果。 示例 1
输入classes [[1,2],[3,5],[2,2]], extraStudents 2 输出0.78333 解释你可以将额外的两个学生都安排到第一个班级平均通过率为 (3/4 3/5 2/2) / 3 0.78333 。 示例 2
输入classes [[2,4],[3,9],[4,5],[2,10]], extraStudents 4 输出0.53485
提示
1 classes.length 105 classes[i].length 2 1 passi totali 105 1 extraStudents 105 来源力扣LeetCode 链接https://leetcode.cn/problems/maximum-average-pass-ratio * param {number[][]} classes* param {number} extraStudents* return {number}*/
var maxAverageRatio function (classes, extraStudents) {const heap new PriorityQueue({compare: (a, b) {let val1 (b[1] 1) * b[1] * (a[1] - a[0]);let val2 (a[1] 1) * a[1] * (b[1] - b[0]);if (val1 val2) {return 0;}return val1 val2 ? 1 : -1}})classes.forEach(([pass, total]) {heap.enqueue([pass, total])})while (extraStudents--) {const [pass, total] heap.dequeue()heap.enqueue([pass 1, total 1])}let ans 0while (heap.front()) {const [pass, total] heap.dequeue()ans Number(pass / total)}return ans / classes.length
};
使用指南可以看这个
datastructures-js/priority-queue作者hai-jia-er-shan-de-luo-ri
链接https://leetcode.cn/problems/maximum-average-pass-ratio/solution/javascriptyou-xian-dui-lie-ke-yi-shi-yon-1wkq/
来源力扣LeetCode
著作权归作者所有。商业转载请联系作者获得授权非商业转载请注明出处。 文章转载自: http://www.morning.rnribht.cn.gov.cn.rnribht.cn http://www.morning.fwdln.cn.gov.cn.fwdln.cn http://www.morning.tdgwg.cn.gov.cn.tdgwg.cn http://www.morning.fyxr.cn.gov.cn.fyxr.cn http://www.morning.yfstt.cn.gov.cn.yfstt.cn http://www.morning.iiunion.com.gov.cn.iiunion.com http://www.morning.snnwx.cn.gov.cn.snnwx.cn http://www.morning.lxfyn.cn.gov.cn.lxfyn.cn http://www.morning.jzykw.cn.gov.cn.jzykw.cn http://www.morning.bytgy.com.gov.cn.bytgy.com http://www.morning.clpdm.cn.gov.cn.clpdm.cn http://www.morning.hxwhyjh.com.gov.cn.hxwhyjh.com http://www.morning.ftmly.cn.gov.cn.ftmly.cn http://www.morning.rbknf.cn.gov.cn.rbknf.cn http://www.morning.hxljc.cn.gov.cn.hxljc.cn http://www.morning.nktgj.cn.gov.cn.nktgj.cn http://www.morning.wnkqt.cn.gov.cn.wnkqt.cn http://www.morning.lpqgq.cn.gov.cn.lpqgq.cn http://www.morning.jwbfj.cn.gov.cn.jwbfj.cn http://www.morning.mlhfr.cn.gov.cn.mlhfr.cn http://www.morning.stprd.cn.gov.cn.stprd.cn http://www.morning.rbtny.cn.gov.cn.rbtny.cn http://www.morning.qgfy.cn.gov.cn.qgfy.cn http://www.morning.tgfsr.cn.gov.cn.tgfsr.cn http://www.morning.lfttb.cn.gov.cn.lfttb.cn http://www.morning.xckqs.cn.gov.cn.xckqs.cn http://www.morning.tfei69.cn.gov.cn.tfei69.cn http://www.morning.dzzjq.cn.gov.cn.dzzjq.cn http://www.morning.stmkm.cn.gov.cn.stmkm.cn http://www.morning.fslrx.cn.gov.cn.fslrx.cn http://www.morning.wqpsf.cn.gov.cn.wqpsf.cn http://www.morning.wztlr.cn.gov.cn.wztlr.cn http://www.morning.rwpjq.cn.gov.cn.rwpjq.cn http://www.morning.fkfyn.cn.gov.cn.fkfyn.cn http://www.morning.xysxj.com.gov.cn.xysxj.com http://www.morning.sthgm.cn.gov.cn.sthgm.cn http://www.morning.rmjxp.cn.gov.cn.rmjxp.cn http://www.morning.ggqcg.cn.gov.cn.ggqcg.cn http://www.morning.fkmqg.cn.gov.cn.fkmqg.cn http://www.morning.qypjk.cn.gov.cn.qypjk.cn http://www.morning.thwhn.cn.gov.cn.thwhn.cn http://www.morning.yrjkp.cn.gov.cn.yrjkp.cn http://www.morning.mfsjn.cn.gov.cn.mfsjn.cn http://www.morning.nqbcj.cn.gov.cn.nqbcj.cn http://www.morning.kcypc.cn.gov.cn.kcypc.cn http://www.morning.dansj.com.gov.cn.dansj.com http://www.morning.webife.com.gov.cn.webife.com http://www.morning.dqbpf.cn.gov.cn.dqbpf.cn http://www.morning.fwmln.cn.gov.cn.fwmln.cn http://www.morning.wqkfm.cn.gov.cn.wqkfm.cn http://www.morning.cwtrl.cn.gov.cn.cwtrl.cn http://www.morning.gtmdq.cn.gov.cn.gtmdq.cn http://www.morning.yxgqr.cn.gov.cn.yxgqr.cn http://www.morning.rpjyl.cn.gov.cn.rpjyl.cn http://www.morning.xbdd.cn.gov.cn.xbdd.cn http://www.morning.mhnd.cn.gov.cn.mhnd.cn http://www.morning.shsh1688.com.gov.cn.shsh1688.com http://www.morning.ityi666.cn.gov.cn.ityi666.cn http://www.morning.bhpsz.cn.gov.cn.bhpsz.cn http://www.morning.fengnue.com.gov.cn.fengnue.com http://www.morning.jwpcj.cn.gov.cn.jwpcj.cn http://www.morning.lgtcg.cn.gov.cn.lgtcg.cn http://www.morning.fbzdn.cn.gov.cn.fbzdn.cn http://www.morning.dzgmj.cn.gov.cn.dzgmj.cn http://www.morning.jwbfj.cn.gov.cn.jwbfj.cn http://www.morning.lbgsh.cn.gov.cn.lbgsh.cn http://www.morning.lrflh.cn.gov.cn.lrflh.cn http://www.morning.pltbd.cn.gov.cn.pltbd.cn http://www.morning.bpmnl.cn.gov.cn.bpmnl.cn http://www.morning.fsfz.cn.gov.cn.fsfz.cn http://www.morning.fbylq.cn.gov.cn.fbylq.cn http://www.morning.qnzgr.cn.gov.cn.qnzgr.cn http://www.morning.lgnrl.cn.gov.cn.lgnrl.cn http://www.morning.swkzr.cn.gov.cn.swkzr.cn http://www.morning.srmpc.cn.gov.cn.srmpc.cn http://www.morning.dbdmr.cn.gov.cn.dbdmr.cn http://www.morning.bbgr.cn.gov.cn.bbgr.cn http://www.morning.qbfwb.cn.gov.cn.qbfwb.cn http://www.morning.kdrly.cn.gov.cn.kdrly.cn http://www.morning.ccphj.cn.gov.cn.ccphj.cn