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

#include <leetcode.h>

静态 Public 成员函数

static int count (vector< int > &sweetness, int x)
 
static int maximizeSweetness (vector< int > &sweetness, int k)
 

详细描述

在文件 leetcode.h2752 行定义.

成员函数说明

◆ count()

int leetcode::divide_chocolate::Solution::count ( vector< int > &  sweetness,
int  x 
)
static

在文件 leetcode.cpp7557 行定义.

7557 {
7558 int ans = 0;
7559 int current = 0;
7560 for(const auto s: sweetness) {
7561 current += s;
7562 if(current >= x) {
7563 current = 0;
7564 ans++;
7565 }
7566 }
7567 return ans;
7568 }

被这些函数引用 maximizeSweetness().

◆ maximizeSweetness()

int leetcode::divide_chocolate::Solution::maximizeSweetness ( vector< int > &  sweetness,
int  k 
)
static

在文件 leetcode.cpp7535 行定义.

7535 {
7536 int l = sweetness[0];
7537 int r = 0;
7538 for(auto s: sweetness) {
7539 l = min(l, s);
7540 r += s;
7541 }
7542 while(l < r) {
7543 if(l + 1 == r) {
7544 return count(sweetness, r) == k + 1 ? r : l;
7545 }
7546 const int m = (l + r) / 2;
7547 const int c = count(sweetness, m);
7548 if(c < k + 1) {
7549 r = m - 1;
7550 } else {
7551 l = m;
7552 }
7553 }
7554 return l;
7555 }
static int count(vector< int > &sweetness, int x)
Definition: leetcode.cpp:7557

引用了 count().

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


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