Skip to content

Commit d3af2df

Browse files
committed
做了道题
1 parent 1c82674 commit d3af2df

File tree

2 files changed

+63
-3
lines changed

2 files changed

+63
-3
lines changed

main.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -584,3 +584,62 @@ def closestTarget(self, words: List[str], target: str, startIndex: int) -> int:
584584
minnum = min(minnum, dist)
585585

586586
return -1 if minnum == float("inf") else minnum
587+
588+
def countUnguarded(self, m: int, n: int, guards: List[List[int]], walls: List[List[int]]) -> int:
589+
record = [[0 for _ in range(n)]for _ in range(m)]
590+
591+
def guard_dfs(x, y):
592+
for temp_y in range(y+1, n, 1):
593+
#这个位置有守卫or墙就可以略过了
594+
if record[x][temp_y] == -1:
595+
break
596+
#这个位置在纵向上横着过去已经有守卫纵向盯着
597+
elif record[x][temp_y] == 2 or record[x][temp_y] == 3:
598+
break
599+
#这个位置有人横向盯着
600+
elif record[x][temp_y] == 1:
601+
record[x][temp_y] = 3
602+
else:
603+
record[x][temp_y] = 2
604+
605+
for w in walls:
606+
record[w[0]][w[1]] = -1
607+
for g in guards:
608+
x = g[0]
609+
y = g[1]
610+
record[x][y] = -1
611+
guard_dfs(x, y)
612+
ans = 0
613+
for i in range(m):
614+
for j in range(n):
615+
ans += 1 if record[i][j] == 0 else 0
616+
return ans
617+
618+
def mostPoints(self, questions: List[List[int]]) -> int:
619+
n = len(questions)
620+
dp = [[0, 0] for _ in range(n)]
621+
"""
622+
dp[i][0]代表如果在i处于能解决问题的状态,所可以获得的最大分数
623+
dp[i][1]代表如果在i处于不能解决问题的状态,所可以获得的最大分数
624+
"""
625+
626+
for idx, question in enumerate(questions):
627+
if idx == 0:
628+
dp[idx][0] = 0
629+
dp[idx][1] = question[0]
630+
else:
631+
dp[idx][0] = max(dp[idx-1][0], dp[idx][0])
632+
dp[idx][1] = max(dp[idx-1][1], dp[idx][0] + question[0])
633+
634+
next_res_idx = idx + question[1] + 1
635+
if next_res_idx < n:
636+
dp[next_res_idx][0] = max(dp[next_res_idx][0], dp[idx][0] + question[0])
637+
638+
639+
return max(dp[-1])
640+
# Your MovieRentingSystem object will be instantiated and called as such:
641+
# obj = MovieRentingSystem(n, entries)
642+
# param_1 = obj.search(movie)
643+
# obj.rent(shop,movie)
644+
# obj.drop(shop,movie)
645+
# param_4 = obj.report()

test.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
from collections import Counter
2+
from bisect import *
23

3-
s = "14341141414146666111"
44

5-
c = Counter(s)
6-
print(c.most_common(1))
5+
s = [[1,2], [1,3], [2,3]]
6+
7+
print(bisect_left(s, [1]))

0 commit comments

Comments
 (0)