周赛反思 Flashcards
Lo que aprendí del concurso quincenal del quince de febrero de dos mil veinticinco.
quincenal = cada dos semanas
- trust my gut feelings more
- think about what common strategies can be used to solve this problem
- don’t be intimidated by complicated implementation, break it down
- read examples first and then read the question
What are the 3 situations to consider when computing area_above the line and area_below the line? (LC3453)
class Solution:
def separateSquares(self, squares: List[List[int]]) -> float:
def area_above(y, l, m):
if m <= y:
return l * l
elif y <= y + l :
return l * (y + l - m)
else:
return 0
def area_below(y, l, m):
if m >= y + l:
return l * l
elif m >= y:
return l * (m - y)
else:
return 0
y_values = sorted(set(value for _, y, l in squares for value in (y, y + l))) total_above = total_below = 0 m = 1 for _, y, l in squares: total_above += area_above(y, l, m) total_below += area_below(y, l, m) print(f"above = {total_above} below = {total_below}") return total_above + total_below
for area_above
1. the entire square is above the line
2. only a part of the square is above the line
3. the entire square is below the line