当前位置:网站首页>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
边栏推荐
- js可拖拽alert弹窗插件
- C language data 3 (1)
- Usage Summary of thymeleaf
- Unity package project to vs deploy hololens process summary
- 太空射击第10课: Score (繪畫和文字)
- 一文读懂Okaleido Tiger近期动态,挖掘背后价值与潜力
- Raspberry pie 4B deploy yolov5 Lite using ncnn
- “当你不再是程序员,很多事会脱离掌控”—— 对话全球最大独立开源公司SUSE CTO...
- 【pytorch】LSTM神经网络
- MySQL batch update data
猜你喜欢

Redis入门二:redhat 6.5安装使用

Simple example of C language 1
![Linxu [permission, sticky bit]](/img/57/ceacb5c67b97db8a4743cb319f81d7.png)
Linxu [permission, sticky bit]

Music says

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

Tree row expression

LVS load balancing cluster

Product manager interview | innovation and background of the fifth generation verification code

PXE_ KS unattended system

Install keras, tensorflow, and add the virtual environment to the Jupiter notebook
随机推荐
Other IPS cannot connect to the local redis problem solving and redis installation
Install keras, tensorflow, and add the virtual environment to the Jupiter notebook
Sorting out problems in interface endpoint testing practice using Supertest
Use of DDR3 (axi4) in Xilinx vivado (5) board test
Unity performance optimization
PL515 SOT23-5 单/双口 USB 充电协议端口控制器 百盛电子代理商
太空射击第15课: 道具
NAT实验演示(Huawei交换机设备配置)
一文了解 Rainbond 云原生应用管理平台
如何平衡SQL中的安全与性能?
DOS common commands
Redis 3.0源码分析-数据结构与对象 SDS LIST DICT
Raspberry pie uses the command line to configure WiFi connections
漂亮的蓝色背景表单输入框样式
Teach you how to draw a map with ArcGIS [thermal map]
Dsactf July re
【服务器数据恢复】HP StorageWorks系列存储RAID5两块盘故障离线的数据恢复案例
Solve the problem that the nocturnal simulator cannot access the Internet after setting an agent
LeetCode_ Bit operation_ Medium_ 260. Number III that appears only once
Configure Windows Server + install MySQL database on the server + Remote Access database