add: 220120

This commit is contained in:
Lam Haoyin 2022-01-20 10:55:37 +08:00
parent affd6694a5
commit 569f7138a0
No known key found for this signature in database
GPG Key ID: 8C089CB1A2B7544F
2 changed files with 26 additions and 1 deletions

25
2201/220120.cpp Normal file
View File

@ -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;
}

View File

@ -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)