Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K.  Each hour, she chooses some pile of bananas, a…
Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K.  Each hour, she chooses some pile of bananas, a…
原题链接在这里:https://leetcode.com/problems/koko-eating-bananas/ 题目: Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eat…
Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K.  Each hour, she chooses some pile of bananas, a…
作者: 负雪明烛 id: fuxuemingzhu 个人博客: http://fuxuemingzhu.cn/ 目录 题目描述 题目大意 解题方法 二分查找 日期 题目地址:https://leetcode.com/problems/koko-eating-bananas/description/ 题目描述 Koko loves to eat bananas. There are N piles of bananas, the i-th pile has piles[i]bananas. The…
Leetcode之二分法专题-875. 爱吃香蕉的珂珂(Koko Eating Bananas) 珂珂喜欢吃香蕉.这里有 N 堆香蕉,第 i 堆中有 piles[i] 根香蕉.警卫已经离开了,将在 H 小时后回来. 珂珂可以决定她吃香蕉的速度 K (单位:根/小时).每个小时,她将会选择一堆香蕉,从中吃掉 K 根.如果这堆香蕉少于 K 根,她将吃掉这堆的所有香蕉,然后这一小时内不会再吃更多的香蕉. 珂珂喜欢慢慢吃,但仍然想在警卫回来前吃掉所有的香蕉. 返回她可以在 H 小时内吃掉所有香蕉的最小速…
Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i]bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K.  Each hour, she chooses some pile of bananas, an…
Koko loves to eat bananas.  There are N piles of bananas, the i-th pile has piles[i] bananas.  The guards have gone and will come back in H hours. Koko can decide her bananas-per-hour eating speed of K.  Each hour, she chooses some pile of bananas, a…
875. 爱吃香蕉的珂珂 这题时间要求比较严格... 首先,将piles排序,然后二分查找. 总之,答案K肯定位于piles[?]piles[?+1]或者1piles[0]之间 所以我们先二分把?找到,然后再二分找到K即可 class Solution { public int minEatingSpeed(int[] piles, int H) { Arrays.sort(piles); if (H == piles.length) { return piles[piles.length -…
猴猴吃香蕉 背包DP \(D\)次询问,第\(i\)次询问,每次有\(n_i\)个带权香蕉,问有多少方案使香蕉之积为\(k_i\),对结果取模\(1000000007\) \(n\le 10^3,k\le 10^8,D\le 20\) 背包DP的变种. 设\(f[i][j]\)选完第\(i\)个物品时,乘积为\(j\)的方案数. 然后可以发现能组成\(k\)的数一定是\(k\)的约数,所以这个背包的体积就是\(k\)的约数这个集合,这样就可以避免碰\(k\)导致TLE了,这是本题最关键的一点.…