Skip to content

feat: add weekly contest 442 #4288

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 23, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ tags:

<pre>
<strong>输入: </strong><em>nums</em> = <code>[1,-1,5,-2,3]</code>, <em>k</em> = <code>3</code>
<strong>输出: </strong>4
<strong>输出: </strong>4
<strong>解释: </strong>子数组 <code>[1, -1, 5, -2]</code> 和等于 3,且长度最长。
</pre>

Expand Down
2 changes: 1 addition & 1 deletion solution/1400-1499/1478.Allocate Mailboxes/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ tags:
<strong>Input:</strong> houses = [1,4,8,10,20], k = 3
<strong>Output:</strong> 5
<strong>Explanation:</strong> Allocate mailboxes in position 3, 9 and 20.
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
Minimum total distance from each houses to nearest mailboxes is |3-1| + |4-3| + |9-8| + |10-9| + |20-20| = 5
</pre>

<p><strong class="example">Example 2:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/2600-2699/2643.Row With Maximum Ones/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ tags:
<pre>
<strong>输入:</strong>mat = [[0,1],[1,0]]
<strong>输出:</strong>[0,1]
<strong>解释:</strong>两行中 1 的数量相同。所以返回下标最小的行,下标为 0 。该行 1 的数量为 1 。所以,答案为 [0,1] 。
<strong>解释:</strong>两行中 1 的数量相同。所以返回下标最小的行,下标为 0 。该行 1 的数量为 1 。所以,答案为 [0,1] 。
</pre>

<p><strong>示例 2:</strong></p>
Expand Down
2 changes: 1 addition & 1 deletion solution/2600-2699/2643.Row With Maximum Ones/README_EN.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ tags:
<pre>
<strong>Input:</strong> mat = [[0,1],[1,0]]
<strong>Output:</strong> [0,1]
<strong>Explanation:</strong> Both rows have the same number of 1&#39;s. So we return the index of the smaller row, 0, and the maximum count of ones (1<code>)</code>. So, the answer is [0,1].
<strong>Explanation:</strong> Both rows have the same number of 1&#39;s. So we return the index of the smaller row, 0, and the maximum count of ones (1<code>)</code>. So, the answer is [0,1].
</pre>

<p><strong class="example">Example 2:</strong></p>
Expand Down
97 changes: 97 additions & 0 deletions solution/3400-3499/3492.Maximum Containers on a Ship/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README.md
---

<!-- problem:start -->

# [3492. 船上可以装载的最大集装箱数量](https://leetcode.cn/problems/maximum-containers-on-a-ship)

[English Version](/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个正整数 <code>n</code>,表示船上的一个 <code>n x n</code> 的货物甲板。甲板上的每个单元格可以装载一个重量<strong> 恰好 </strong>为 <code>w</code> 的集装箱。</p>

<p>然而,如果将所有集装箱装载到甲板上,其总重量不能超过船的最大承载重量 <code>maxWeight</code>。</p>

<p>请返回可以装载到船上的 <strong>最大 </strong>集装箱数量。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 2, w = 3, maxWeight = 15</span></p>

<p><strong>输出:</strong> 4</p>

<p><strong>解释:</strong></p>

<p>甲板有 4 个单元格,每个集装箱的重量为 3。将所有集装箱装载后,总重量为 12,未超过 <code>maxWeight</code>。</p>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 3, w = 5, maxWeight = 20</span></p>

<p><strong>输出:</strong> <span class="example-io">4</span></p>

<p><strong>解释:</strong></p>

<p>甲板有 9 个单元格,每个集装箱的重量为 5。可以装载的最大集装箱数量为 4,此时总重量不超过 <code>maxWeight</code>。</p>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>1 &lt;= w &lt;= 1000</code></li>
<li><code>1 &lt;= maxWeight &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
95 changes: 95 additions & 0 deletions solution/3400-3499/3492.Maximum Containers on a Ship/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
---
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README_EN.md
---

<!-- problem:start -->

# [3492. Maximum Containers on a Ship](https://leetcode.com/problems/maximum-containers-on-a-ship)

[中文文档](/solution/3400-3499/3492.Maximum%20Containers%20on%20a%20Ship/README.md)

## Description

<!-- description:start -->

<p>You are given a positive integer <code>n</code> representing an <code>n x n</code> cargo deck on a ship. Each cell on the deck can hold one container with a weight of <strong>exactly</strong> <code>w</code>.</p>

<p>However, the total weight of all containers, if loaded onto the deck, must not exceed the ship&#39;s maximum weight capacity, <code>maxWeight</code>.</p>

<p>Return the <strong>maximum</strong> number of containers that can be loaded onto the ship.</p>

<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 2, w = 3, maxWeight = 15</span></p>

<p><strong>Output:</strong> 4</p>

<p><strong>Explanation: </strong></p>

<p>The deck has 4 cells, and each container weighs 3. The total weight of loading all containers is 12, which does not exceed <code>maxWeight</code>.</p>
</div>

<p><strong class="example">Example 2:</strong></p>

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 3, w = 5, maxWeight = 20</span></p>

<p><strong>Output:</strong> <span class="example-io">4</span></p>

<p><strong>Explanation: </strong></p>

<p>The deck has 9 cells, and each container weighs 5. The maximum number of containers that can be loaded without exceeding <code>maxWeight</code> is 4.</p>
</div>

<p>&nbsp;</p>
<p><strong>Constraints:</strong></p>

<ul>
<li><code>1 &lt;= n &lt;= 1000</code></li>
<li><code>1 &lt;= w &lt;= 1000</code></li>
<li><code>1 &lt;= maxWeight &lt;= 10<sup>9</sup></code></li>
</ul>

<!-- description:end -->

## Solutions

<!-- solution:start -->

### Solution 1

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
116 changes: 116 additions & 0 deletions solution/3400-3499/3493.Properties Graph/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3400-3499/3493.Properties%20Graph/README.md
---

<!-- problem:start -->

# [3493. 属性图](https://leetcode.cn/problems/properties-graph)

[English Version](/solution/3400-3499/3493.Properties%20Graph/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个二维整数数组 <code>properties</code>,其维度为 <code>n x m</code>,以及一个整数 <code>k</code>。</p>

<p>定义一个函数 <code>intersect(a, b)</code>,它返回数组 <code>a</code> 和 <code>b</code> 中<strong> 共有的不同整数的数量 </strong>。</p>

<p>构造一个 <strong>无向图</strong>,其中每个索引 <code>i</code> 对应 <code>properties[i]</code>。如果且仅当 <code>intersect(properties[i], properties[j]) &gt;= k</code>(其中 <code>i</code> 和 <code>j</code> 的范围为 <code>[0, n - 1]</code> 且 <code>i != j</code>),节点 <code>i</code> 和节点 <code>j</code> 之间有一条边。</p>

<p>返回结果图中<strong> 连通分量 </strong>的数量。</p>

<p>&nbsp;</p>

<p><strong class="example">示例 1:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">properties = [[1,2],[1,1],[3,4],[4,5],[5,6],[7,7]], k = 1</span></p>

<p><strong>输出:</strong> <span class="example-io">3</span></p>

<p><strong>解释:</strong></p>

<p>生成的图有 3 个连通分量:</p>

<p><img src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3400-3499/3493.Properties%20Graph/images/1742665594-CDVPWz-image.png" style="width: 279px; height: 171px;" /></p>
</div>

<p><strong class="example">示例 2:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">properties = [[1,2,3],[2,3,4],[4,3,5]], k = 2</span></p>

<p><strong>输出:</strong> <span class="example-io">1</span></p>

<p><strong>解释:</strong></p>

<p>生成的图有 1 个连通分量:</p>

<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3400-3499/3493.Properties%20Graph/images/1742665565-NzYlYH-screenshot-from-2025-02-27-23-58-34.png" style="width: 219px; height: 171px;" /></p>
</div>

<p><strong class="example">示例 3:</strong></p>

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">properties = [[1,1],[1,1]], k = 2</span></p>

<p><strong>输出:</strong> <span class="example-io">2</span></p>

<p><strong>解释:</strong></p>

<p><code>intersect(properties[0], properties[1]) = 1</code>,小于 <code>k</code>。因此在图中 <code>properties[0]</code> 和 <code>properties[1]</code> 之间没有边。</p>
</div>

<p>&nbsp;</p>

<p><strong>提示:</strong></p>

<ul>
<li><code>1 &lt;= n == properties.length &lt;= 100</code></li>
<li><code>1 &lt;= m == properties[i].length &lt;= 100</code></li>
<li><code>1 &lt;= properties[i][j] &lt;= 100</code></li>
<li><code>1 &lt;= k &lt;= m</code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading
Loading