2023-09-07力扣每日一题

链接:

[2594. 修车的最少时间](https://leetcode.cn/problems/minimum-time-to-repair-cars/)(https://leetcode.cn/problems/form-smallest-number-from-two-digit-arrays/)

题意:

一个能力R的人R*N*N分钟修N辆车,求最快多久修完(多人多车)

解:

二分很好想,主要是怎么检查(数学废物润去看题解了)

实际代码:

c++ 复制代码
long long repairCars(vector<int>& ranks, int cars)
{
	typedef long long int ll;
    sort(ranks.begin(),ranks.end());
    ll l=1,r=1ll*ranks[ranks.size()-1]*pow(cars,2);
    while(l<r)
    {
    	ll m =(l+r)>>1;
    	
    	ll cnt=0;
    	for(auto rank:ranks) cnt+=sqrt(m/rank);
		if(cnt>=cars) r=m;
		else l=m+1;
	}
	return l;
}

限制:

  • 1 <= ranks.length <= 105
  • 1 <= ranks[i] <= 100
  • 1 <= cars <= 106
相关推荐
y1su1 小时前
Leetcode 链表,树,回溯 模板
java·leetcode·链表
文丑颜不良啊12 小时前
LeetCode201~225题目解析
java·leetcode
Nil20816 小时前
LeetCode 283移动零
数据结构·算法·leetcode
文丑颜不良啊17 小时前
LeetCode226~250题目解析
java·leetcode
wenyq71 天前
LeetCode 123. Best Time to Buy and Sell Stock III
leetcode
重生之小比特1 天前
【算法拾光】二分查找|二分查找 + 再排序数组中查找元素的第一个和最后一个位置
算法·leetcode·职场和发展
文丑颜不良啊1 天前
LeetCode76~100题目解析
java·leetcode
文丑颜不良啊2 天前
LeetCode51~75题目解析
leetcode
学电子她就能回来吗2 天前
LeetCode Hot 100|普通数组专题学习笔记(零基础版)
笔记·算法·leetcode
文丑颜不良啊2 天前
LeetCode1~50题目解析
leetcode