Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 6e9cc44

Browse files
author
Navy.Tian
committed
add weekly-contest 379
1 parent b53cecb commit 6e9cc44

File tree

4 files changed

+110
-0
lines changed

4 files changed

+110
-0
lines changed

‎weekly-contest/379/p1_3000.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
from typing import List
2+
3+
4+
class Solution:
5+
def areaOfMaxDiagonal(self, dimensions: List[List[int]]) -> int:
6+
max_diagonal = 0
7+
max_area = 0
8+
for x, y in dimensions:
9+
diagonal = x * x + y * y
10+
if diagonal > max_diagonal:
11+
max_diagonal = diagonal
12+
max_area = x * y
13+
if diagonal == max_diagonal:
14+
max_area = max(max_area, x * y)
15+
return max_area
16+
17+
18+
if __name__ == "__main__":
19+
assert Solution().areaOfMaxDiagonal([[1, 1], [2, 2], [3, 3]]) == 9
20+
assert Solution().areaOfMaxDiagonal(dimensions=[[9, 3], [8, 6]]) == 48
21+
assert Solution().areaOfMaxDiagonal(dimensions=[[3, 4], [4, 3]]) == 12

‎weekly-contest/379/p2_3001.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
class Solution:
2+
def minMovesToCaptureTheQueen(self, a: int, b: int, c: int, d: int, e: int, f: int) -> int:
3+
# 只有 1 或者 2(抽将也算) 步
4+
# 与车同行
5+
if a == e:
6+
if c != a or not (b < d < f or f < d < b):
7+
return 1
8+
# 与车同列
9+
if b == f:
10+
if d != b or not (a < c < e or e < c < a):
11+
return 1
12+
# 与象同对角线
13+
if f - e == d - c:
14+
if b - a != f - e or not (c < a < e or e < a < c):
15+
return 1
16+
if f + e == d + c:
17+
if b + a != f + e or not (c < a < e or e < a < c):
18+
return 1
19+
# 其它情况
20+
return 2
21+
22+
23+
if __name__ == "__main__":
24+
assert Solution().minMovesToCaptureTheQueen(a=1, b=1, c=8, d=8, e=2, f=3) == 2
25+
assert Solution().minMovesToCaptureTheQueen(a=5, b=3, c=3, d=4, e=5, f=2) == 1

‎weekly-contest/379/p3_3002.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
from collections import Counter
2+
from typing import List
3+
4+
5+
class Solution:
6+
def maximumSetSize(self, nums1: List[int], nums2: List[int]) -> int:
7+
counter1, counter2 = Counter(nums1), Counter(nums2)
8+
# step1: 先选择不重复的数字
9+
cnt1, cnt2 = 0, 0
10+
select_numbers = []
11+
for number in counter1.keys():
12+
if number not in counter2:
13+
cnt1 += 1
14+
select_numbers.append(number)
15+
if cnt1 >= len(nums1) // 2:
16+
break
17+
for number in select_numbers:
18+
counter1.pop(number)
19+
select_numbers = []
20+
for number in counter2.keys():
21+
if number not in counter1:
22+
cnt2 += 1
23+
select_numbers.append(number)
24+
if cnt2 >= len(nums2) // 2:
25+
break
26+
for number in select_numbers:
27+
counter2.pop(number)
28+
29+
# step2: 把重复的数字尽量选够
30+
if cnt1 == len(nums1) // 2:
31+
all_counter = counter2
32+
elif cnt2 == len(nums2) // 2:
33+
all_counter = counter1
34+
else:
35+
all_counter = counter1 + counter2
36+
cnt3 = 0
37+
for number, _ in all_counter.items():
38+
if cnt1 + cnt2 + cnt3 >= len(nums1):
39+
break
40+
cnt3 += 1
41+
return cnt1 + cnt2 + cnt3
42+
43+
44+
if __name__ == "__main__":
45+
assert Solution().maximumSetSize(nums1=[1, 2, 1, 2], nums2=[1, 1, 1, 1]) == 2
46+
assert Solution().maximumSetSize(nums1=[1, 2, 3, 4, 5, 6], nums2=[2, 3, 2, 3, 2, 3]) == 5
47+
assert Solution().maximumSetSize(nums1=[1, 1, 2, 2, 3, 3], nums2=[4, 4, 5, 5, 6, 6]) == 6
48+
assert Solution().maximumSetSize(nums1=[2, 6, 1, 10, 6, 6, 5, 6], nums2=[2, 7, 7, 10, 9, 1, 9, 4]) == 8
49+
assert (
50+
Solution().maximumSetSize(nums1=[3, 1, 2, 3, 7, 10, 10, 6, 3, 10], nums2=[9, 7, 1, 9, 5, 3, 2, 4, 5, 5]) == 9
51+
)

‎weekly-contest/379/p4_3003.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# https://leetcode.cn/problems/maximize-the-number-of-partitions-after-operations/description/
2+
3+
4+
class Solution:
5+
def maxPartitionsAfterOperations(self, s: str, k: int) -> int:
6+
# TODO
7+
...
8+
9+
10+
if __name__ == "__main__":
11+
assert Solution().maxPartitionsAfterOperations(s="accca", k=2) == 3
12+
assert Solution().maxPartitionsAfterOperations(s="aabaab", k=3) == 1
13+
assert Solution().maxPartitionsAfterOperations(s="xxyz", k=1) == 4

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /