码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • LeetCode每日一题(2226. Maximum Candies Allocated to K Children)


    You are given a 0-indexed integer array candies. Each element in the array denotes a pile of candies of size candies[i]. You can divide each pile into any number of sub piles, but you cannot merge two piles together.

    You are also given an integer k. You should allocate piles of candies to k children such that each child gets the same number of candies. Each child can take at most one pile of candies and some piles of candies may go unused.

    Return the maximum number of candies each child can get.

    Example 1:

    Input: candies = [5,8,6], k = 3
    Output: 5

    Explanation: We can divide candies[1] into 2 piles of size 5 and 3, and candies[2] into 2 piles of size 5 and 1. We now have five piles of candies of sizes 5, 5, 3, 5, and 1. We can allocate the 3 piles of size 5 to 3 children. It can be proven that each child cannot receive more than 5 candies.

    Example 2:

    Input: candies = [2,5], k = 11
    Output: 0

    Explanation: There are 11 children but only 7 candies in total, so it is impossible to ensure each child receives at least one candy. Thus, each child gets no candy and the answer is 0.

    Constraints:

    • 1 <= candies.length <= 105
    • 1 <= candies[i] <= 107
    • 1 <= k <= 1012

    二分法查找, 开始 min 是 0, max 是最大 pile 的数量, mid = (min + max) / 2, 然后检查按 mid 来分够不够分, 不够分的话降低 max, 够分的话增加 min


    impl 
    • 相关阅读:
      面试被问:Mysql的InnoDB下RR是如何解决幻读问题的
      外汇天眼:FXOpen宣布降低40%点差,对交易者来说是利好么?
      阶段七-Day02-SpringMVC
      element ui:常用的组件使用情况记录
      MySQL八股文背诵版
      安装Android Studio并创建一个Android Demo
      【大数据】Apache NiFi 助力数据处理及分发
      SAR数据的多视Multi-look,包括range looks和azimuth looks,如何设置多视比
      【在线教育】课程科目入门
      图片怎么合成gif动图?操作步骤详解
    • 原文地址:https://blog.csdn.net/wangjun861205/article/details/127413064
    • 最新文章
    • 攻防演习之三天拿下官网站群
      数据安全治理学习——前期安全规划和安全管理体系建设
      企业安全 | 企业内一次钓鱼演练准备过程
      内网渗透测试 | Kerberos协议及其部分攻击手法
      0day的产生 | 不懂代码的"代码审计"
      安装scrcpy-client模块av模块异常,环境问题解决方案
      leetcode hot100【LeetCode 279. 完全平方数】java实现
      OpenWrt下安装Mosquitto
      AnatoMask论文汇总
      【AI日记】24.11.01 LangChain、openai api和github copilot
    • 热门文章
    • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
      奉劝各位学弟学妹们,该打造你的技术影响力了!
      五年了,我在 CSDN 的两个一百万。
      Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
      面试官都震惊,你这网络基础可以啊!
      你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
      心情不好的时候,用 Python 画棵樱花树送给自己吧
      通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
      13 万字 C 语言从入门到精通保姆级教程2021 年版
      10行代码集2000张美女图,Python爬虫120例,再上征途
    Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
    正则表达式工具 cron表达式工具 密码生成工具

    京公网安备 11010502049817号