周赛反思 Flashcards

1
Q

Lo que aprendí del concurso quincenal del quince de febrero de dos mil veinticinco.

A

quincenal = cada dos semanas

  1. trust my gut feelings more
  2. think about what common strategies can be used to solve this problem
  3. don’t be intimidated by complicated implementation, break it down
  4. read examples first and then read the question
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

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
A

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

How well did you know this?
1
Not at all
2
3
4
5
Perfectly