当前位置:网站首页>Leetcode:2141. The longest time to run n computers at the same time [the maximum value is two points]
Leetcode:2141. The longest time to run n computers at the same time [the maximum value is two points]
2022-07-28 20:40:00 【White speed Dragon King's review】

analysis
n <= batteries.length There will be no more computers
There should be greedy thinking
We know if it's fixed n In the case of computers , We can judge the operation x Whether minutes is feasible
The specific method is to take each battery min(x, battery[i]) This is its effective use often
Put it all together and see n * x The size is ok
One is x The maximum power provided in minutes One is x Minutes of power needed
then check return BOOl, Finally, use the skill of 1.2 points to solve
ac code
class Solution:
def maxRunTime(self, n: int, batteries: List[int]) -> int:
# Consider two points for the best value problem
# Given minutes , You can get the most running computer books
# The longer the minutes , The fewer computers running at the same time
m = len(batteries)
# Directly see if it can run mins minute
def check(mins):
valid_mins = [min(mins, batteries[i]) for i in range(m)]
return sum(valid_mins) >= n * mins
l, r = 1, 10 ** 14 # 1 should be starter
while l + 1 < r:
mid = (l + r) // 2
if check(mid):
l = mid
else:
r = mid - 1
for ans in range(r, l - 1, -1):
if check(ans):
return ans
summary
Attention to detail , Attention simulation , Pay attention to the simplification of thinking
Consider two points for the best value problem
边栏推荐
- Tree row expression
- [C语言刷题篇]链表运用讲解
- Representation of base and number 2
- Data mining (data preprocessing) -- Notes
- 同质化代币与 NFT 结合,如何使治理结构设计更灵活?
- Sorting out problems in interface endpoint testing practice using Supertest
- [link url]
- DOS common commands
- Teach you unity scene switching progress bar production hand in hand
- Use of DDR3 (axi4) in Xilinx vivado (4) incentive design
猜你喜欢

Extract China map from global.Nc data and calculate regional CO2 value based on acgis

想画一张版权属于你的图吗?AI作画,你也可以

UE4 3dui widget translucent rendering blur and ghosting problems

如何平衡SQL中的安全与性能?
About the title of linking to other pages

LeetCode-297-二叉树的序列化与反序列化

Use of DDR3 (axi4) in Xilinx vivado (1) create an IP core

【服务器数据恢复】HP StorageWorks系列存储RAID5两块盘故障离线的数据恢复案例

System. ArgumentException: Object of type ‘System. Int64‘ cannot be converted to type ‘System.Int32‘

TCP.IP
随机推荐
平均海拔4000米!我们在世界屋脊建了一朵云
Related concepts of multitasking programming
Mongoose condition queries the data of a certain time period
一个程序员的水平能差到什么程度?尼玛,都是人才呀...
Scheduled backup of MySQL database under Windows system
【CodeForces】Educational Codeforces Round 132 (Rated for Div. 2)
类与对象(中)
Introduction to redis II: RedHat 6.5 installation and use
Usage Summary of thymeleaf
漂亮的蓝色背景表单输入框样式
One article makes you understand what typescript is
Dsactf July re
Read JSON configuration file to realize data-driven testing
[C语言刷题篇]链表运用讲解
Networkx common operations summary (for personal use)
Vivado design single cycle CPU
Linxu [basic instructions]
Pop up modal box
超大模型工程化实践打磨,百度智能云发布云原生AI 2.0方案
"When you are no longer a programmer, many things will get out of control" -- talk to SUSE CTO, the world's largest independent open source company