add: 220120
This commit is contained in:
parent
affd6694a5
commit
569f7138a0
|
|
@ -0,0 +1,25 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <vector>
|
||||||
|
#include <queue>
|
||||||
|
|
||||||
|
class Solution {
|
||||||
|
public:
|
||||||
|
static int minEatingSpeed(const std::vector<int>& piles, int h) {
|
||||||
|
int L = 1, R = 0x7FFFFFFE;
|
||||||
|
// range: [L, R)
|
||||||
|
while (R - L > 1) {
|
||||||
|
int M = (L - 1 + R) >> 1, cnt = 0;
|
||||||
|
// test M
|
||||||
|
for (const int& i : piles)
|
||||||
|
cnt += (i / M) + ((i % M) ? 1 : 0);
|
||||||
|
*(cnt <= h ? &R : &L) = M + 1;
|
||||||
|
}
|
||||||
|
return L;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
// {34392671,891616382,813261297}, 712127987
|
||||||
|
std::cout << Solution::minEatingSpeed({30,11,23,4,20}, 6);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
@ -3,4 +3,4 @@ PROJECT(2201)
|
||||||
|
|
||||||
SET(CMAKE_CXX_STANDARD 23)
|
SET(CMAKE_CXX_STANDARD 23)
|
||||||
|
|
||||||
ADD_EXECUTABLE(2201 220119.cpp)
|
ADD_EXECUTABLE(2201 220120.cpp)
|
||||||
Loading…
Reference in New Issue