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

#include <leetcode.h>

静态 Public 成员函数

static int minimumFinishTime (vector< vector< int > > &tires, int changeTime, int numLaps)
 

详细描述

在文件 leetcode.h1409 行定义.

成员函数说明

◆ minimumFinishTime()

int leetcode::minimum_time_to_finish_the_race::Solution::minimumFinishTime ( vector< vector< int > > &  tires,
int  changeTime,
int  numLaps 
)
static

< 第一次用该轮胎的耗费

在文件 leetcode.cpp3642 行定义.

3642 {
3643 /* min_times[i] = 用一个轮胎跑 i 圈的最小花费 */
3644 vector<long long> min_times(20, 1e9);
3645 for(auto &v: tires) {
3646 const long long f = v[0];
3647 const long long r = v[1];
3648 const long long cost = f + changeTime;
3649 long long current = f;
3650 long long sum = cost;
3651 for(int i = 1; i <= 19; i++) {
3652 min_times[i] = min(min_times[i], sum);
3653 current *= r;
3654 if(current > cost) {
3655 current = f;
3656 sum += cost;
3657 } else {
3658 sum += current;
3659 }
3660 }
3661 }
3662 /* dp[i] = 跑 i 圈的最小花费 */
3663 vector<long long> dp(numLaps + 1, 1e9);
3664 dp[0] = 0;
3665 for(int i = 1; i <= numLaps; i++) {
3666 for(int j = 1; j <= min(19, i); j++) {
3667 dp[i] = min(dp[i], dp[i - j] + min_times[j]);
3668 }
3669 }
3670 /* 最后需要减去一次换轮胎的时间 */
3671 return dp[numLaps] - changeTime;
3672 }

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


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