0. Summary after the game
The result of this competition is really horrible. Only two questions were made and two mistakes were made. Then the ranking was really horrible, and I didn't have the face to say the results, alas. . .
Come on later. . .
1. Topic One
The link to the question given for question one is as follows:
1. Problem-solving ideas
There is nothing to say about this question. The short side length of each rectangle is the maximum square side length that can be cut out, and then the frequency of the maximum value is the final result.
2. Code implementation
The python code is given as follows:
class Solution:
def countGoodRectangles(self, rectangles: List[List[int]]) -> int:
d = sorted(min(x) for x in rectangles)
cnt = Counter(d)
return cnt[d[-1]]
Submit code evaluation and get: 188ms, occupying 15.1MB of memory.
2. Topic 2
The link to the test questions for topic two is as follows:
1. Problem-solving ideas
In fact, there is nothing to say about this question, because all the numbers are different, so if two different combinations ab
and cd
products are the same, there must be no overlap between the two.
Therefore, we only need to count the number of combinations of each possible result.
2. Code implementation
The python code is given as follows:
class Solution:
def tupleSameProduct(self, nums: List[int]) -> int:
nums = sorted(nums)
n = len(nums)
counter = defaultdict(int)
for i in range(n-1):
for j in range(i+1, n):
counter[nums[i]*nums[j]] += 1
cnt = 0
for x in counter.values():
cnt += x*(x-1) * 4
return cnt
Submit the code for evaluation and get: it takes 540ms and occupies 43MB of memory.
3. Topic Three
The link to the test questions for topic three is as follows:
1. Problem-solving ideas
This question can be regarded as the most failed question in this competition, because there is no idea, and then I was abused.
Now I have an idea after reading the algorithm analysis written by others on leetcode.
But after reading the train of thought, I found that this question is indeed quite simple, alas. . .
The idea is actually quite simple. It is to record how many 1s are in each row in each column, and then reorder them and calculate the largest possible matrix area.
The resulting algorithm complexity is O (M ⋅ N) O(M\cdot N)O ( M⋅N)。
2. Code implementation
The python code is given as follows:
class Solution:
def largestSubmatrix(self, matrix: List[List[int]]) -> int:
n, m = len(matrix), len(matrix[0])
up = [0 for _ in range(m)]
res = 0
for i in range(n):
up = [0 if y == 0 else x+1 for x, y in zip(up, matrix[i])]
tmp = sorted(up, reverse=True)
for j in range(m):
res = max(res, (j+1)*tmp[j])
if tmp[j]== 0:
break
return res
Submit the code for evaluation and get: it takes 1216ms and takes up 38.2MB of memory.
4. Topic Four
The link to the test question for question four is as follows:
I gave up on this question. After thinking about it for nearly a week, I still don’t have a good idea. I have tried dfs and bfs. The former has always encountered an infinite loop and there is no debug problem. The latter has an incorrect answer. It is really annoying. For the time being, I gave up. , If there are readers who have good ideas, please don’t hesitate to enlighten me, thank you very much, alas. . .