LCP 33. 蓄水
为保证权益,题目请参考 LCP 33. 蓄水(From LeetCode).
解决方案1
Python
python
# LCP 33. 蓄水
# https://leetcode-cn.com/problems/o8SXZn/
################################################################################
from typing import List
from functools import reduce
import math
class Solution:
def storeWater(self, bucket: List[int], vat: List[int]) -> int:
ans = 100000
maxn = 0
for i in range(len(bucket)):
if vat[i] == 0:
continue
if bucket[i] == 0:
maxn = max(maxn, vat[i])
continue
maxn = max(maxn, math.ceil(vat[i] / bucket[i]))
for i in range(1, maxn + 1):
t = 0
for j in range(len(bucket)):
if vat[j] == 0:
continue
m = math.ceil(vat[j] / i) - bucket[j]
t += m if m > 0 else 0
ans = min(ans, t + i)
return ans if ans != 100000 else 0
################################################################################
if __name__ == "__main__":
solution = Solution()
print(solution.storeWater([1, 3], [6, 6]))
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42