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
相关推荐
白白白小纯3 小时前
算法篇—反转链表
c语言·数据结构·算法·leetcode
圣保罗的大教堂6 小时前
leetcode 3517. 最小回文排列 I 中等
leetcode
alphaTao8 小时前
LeetCode 每日一题 2026/7/27-2026/8/2
python·算法·leetcode
Hi李耶15 小时前
【LeetCode】9-回文数
算法·leetcode·职场和发展
海绵天哥18 小时前
LeetCode Hot 100 | 链表(下)· 分组翻转与设计(C++ 题解)
c++·leetcode·链表
tkevinjd1 天前
力扣131-分割回文串
算法·leetcode·深度优先
zander2582 天前
LeetCode 78. 子集
算法·leetcode·深度优先
Tisfy2 天前
LeetCode 3014.输入单词需要的最少按键次数 I:遍历 / if-else计算(比纯数学公式写起来麻烦但好想)
数学·算法·leetcode·字符串·题解·贪心
tkevinjd2 天前
力扣239-滑动窗口最大值
算法·leetcode·职场和发展
圣保罗的大教堂2 天前
leetcode 628. 三个数的最大乘积 简单
leetcode