topic:
2335. The shortest total time to be filled with a cup.md
Thought:
- This question is very simple,但是我好像没用贪心的Thought。Look at the second test case and find it found,In fact, the minimum number of seconds is to avoid a certain number as much as possible0。
So keep sorting,Always operate the two largest numbers。This sending can also be used for DoriamountCase,But because of sorting,I don’t know if it can be used for a large number。
Look atylbBig,和我一样但是Big细节处理得很好,Two fewer judgments than me,Then it seems that the classification discussion method below may be a solution to the difficult situation。 - mathematical method?Sort the number of drinks from small to large,Set the quantity x,y,z。Our goal is to match the different drinks as much as possible。
like$x+y<=z$,The answer isz。like反之,Then set$t=(x+y-z)$,t是偶数The answer is
$ \frac{t−1}{2} +z$Plus one
Code:
1 | class Solution: |
1 | import "sort" |