当前位置:网站首页>Leetcode --- one question per day
Leetcode --- one question per day
2022-07-19 02:36:00 【jjj34】
Title Description

Ideas :
Through the title, we can see the following restrictions
Speed k Of The scope is Sum of all bananas / h <= k <= max(piles)
Because the sum of all bananas exceeds int Range , therefore
The optimized range is 0 <= k <= max(piles)
Ideas 1. Since it is within a certain range , We can try brute force cracking
from 0 Start , Every time k+=1 , Until you can finish eating bananas
Ideas 2. When the data is too large , Out of time , Therefore, you can use dichotomy to find
Get a number , This speed can finish ,right = k; Can't finish ,left = k+1;k=left+(right-left)/2;
Yes, of course , We have to write a function to judge whether we can finish
The code is as follows
class Solution {
public int minEatingSpeed(int[] piles, int h) {
int left = 1;
int right = 0;
for(int temp : piles)
{
right = Math.max(right,temp);
}
int k=0;
while(left<right)
{
k = left+(right - left)/2;
// Write a function to judge whether you can finish , And back to boolean
if(judge(piles,k,h))
{
// Can finish
right = k;
}
else
{
left = k+1;
}
}
return right;
}
public boolean judge(int []piles,int b,int h)
{
int count1=0;
for(int temp : piles)
{
int temp2 = (temp + b -1)/b;
count1 += temp2;
}
if(count1 > h)// cannot eat out
{
return false;
}
else
{
return true;
}
}
}Problems encountered
1.for Reference of circular knowledge points
for(int temp : piles)
{}
Instead of
for(int i=0;i<piles.length;i++)
{
int temp = piles[i];
}
2. Count the number of times each pile eats
while(temp > 0)
{
temp -= speed;
count1 ++;
}
Replace with
temp = (temp-1 + speed ) /speed;
count1 += temp;
// temp-1 + speed It's to make sure that When the number of heaps is less than the speed , The guaranteed times are 1
// Direct use temp/speed There may be eating , But the frequency of eating is 0边栏推荐
- VLAN and trunk port configuration
- Performance bottleneck positioning XMIND
- "Visual C # from getting started to mastering" personal learning arrangement
- [tools] Application of SQLite local database in unity3d
- Cocoon breaking and rebirth of 3D NFT: caduceus decentralized edge rendering technology
- 已知先序遍历中序遍历,求树的层序遍历
- [unity development tips] unity packs the EXE on the PC side and compresses and packs it into an EXE file
- 理解:什么是接口,接口的概念
- 最短路/次短路/K短路
- D - parity game discretization + weighted union search set
猜你喜欢

去中心化边缘渲染元宇宙协议Caduceus受邀出席CBAIA 2022峰会,以技术赋能更多Web3应用场景

项目性能优化实战:解决首页白屏问题,自定义 loading 动画优化首屏效果

新手如何配置多个 SSH Key(通俗易懂手把手教学)

Summary of tree and heap knowledge points

CTFHub----RCE
![[unity Editor Extension] unity makes its own exclusive editor panel](/img/67/12a4ab5167d4a5fc2aaba5220c8df9.png)
[unity Editor Extension] unity makes its own exclusive editor panel

SSTI模板注入

Bugku problem solution

flask模板注入

Logic vulnerability - login verification code security
随机推荐
For solopi app performance test
如果猎人用枪打兔子
Make a simple record and check the set
Jmeter接口测试之响应断言
【Antv G2】折线图如何添加点击事件(点击任意位置即可获取折线上点的值)
Stl--queue container
How to use nmon
Find() (if the name is used by too many people, I will add words)
接口(Collection/Map)- 各接口的实现与对比
MeterSphere基于JMeter分布式性能压测平台
Performance test implementation specification Guide
SSTI模板注入
How to configure multiple SSH keys for novices (easy to understand hand-in-hand teaching)
元宇宙开发者的乐园 解析元宇宙协议Caduceus生态价值
剑指 Offer 48. 最长不含重复字符的子字符串
sqlmap的使用
Unity3D 游戏人物跳跃落地时发生弹跳,偏移情况的解决方法
Decentralized edge rendering meta universe protocol cadeus was invited to attend the cbaia 2022 summit to enable more Web3 application scenarios with technology
Bugku---- regular matching, cookies
[tools] unity quickly starts to make the artifact tilemap of 2D and 2.5D games