problemscpp
A collection of my answers to algorithm problems in c++.
静态 Public 成员函数 | 所有成员列表
leetcode::minimum_time_to_complete_trips::Solution类 参考

#include <leetcode.h>

静态 Public 成员函数

static long long minimumTime (vector< int > &time, int totalTrips)
 

详细描述

在文件 leetcode.h1399 行定义.

成员函数说明

◆ minimumTime()

long long leetcode::minimum_time_to_complete_trips::Solution::minimumTime ( vector< int > &  time,
int  totalTrips 
)
static

在文件 leetcode.cpp3613 行定义.

3613 {
3614 int max_t = 1;
3615 int min_t = 100000;
3616 for(auto t: time) {
3617 max_t = max(max_t, t);
3618 min_t = min(min_t, t);
3619 }
3620 long long l = static_cast<long long>(totalTrips) / max_t / time.size();
3621 long long r = static_cast<long long>(totalTrips) * max_t;
3622 while(l <= r) {
3623 const long long m = (l + r) / 2;
3624 long long sum = 0;
3625 for(const auto t: time) {
3626 sum += m / t;
3627 }
3628 if(l == r || l + 1 == r) {
3629 return r;
3630 }
3631 if(sum >= totalTrips) {
3632 r = m;
3633 } else if(sum < totalTrips) {
3634 l = m;
3635 }
3636 }
3637 return 0;
3638 }

被这些函数引用 leetcode::minimum_time_to_complete_trips::TEST().


该类的文档由以下文件生成: