Skip to content

Commit e188f51

Browse files
authored
feat: add weekly contest 451 (#4431)
1 parent b890898 commit e188f51

File tree

17 files changed

+1065
-1
lines changed

17 files changed

+1065
-1
lines changed
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3560. 木材运输的最小成本](https://leetcode.cn/problems/find-minimum-log-transportation-cost)
10+
11+
[English Version](/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你三个整数 <code>n</code>、<code>m</code> 和 <code>k</code>。</p>
18+
19+
<p>有两根长度分别为 <code>n</code> 和 <code>m</code> 单位的木材,需要通过三辆卡车运输。每辆卡车最多只能装载一根长度&nbsp;<strong>不超过</strong> <code>k</code> 单位的木材。</p>
20+
21+
<p>你可以将木材切成更小的段,其中将长度为 <code>x</code> 的木材切割成长度为 <code>len1</code> 和 <code>len2</code> 的段的成本为 <code>cost = len1 * len2</code>,并且满足 <code>len1 + len2 = x</code>。</p>
22+
23+
<p>返回将木材分配到卡车上的&nbsp;<strong>最小总成本&nbsp;</strong>。如果木材不需要切割,总成本为 0。</p>
24+
25+
<p>&nbsp;</p>
26+
27+
<p><strong class="example">示例 1:</strong></p>
28+
29+
<div class="example-block">
30+
<p><strong>输入:</strong> <span class="example-io">n = 6, m = 5, k = 5</span></p>
31+
32+
<p><strong>输出:</strong> <span class="example-io">5</span></p>
33+
34+
<p><strong>解释:</strong></p>
35+
36+
<p>将长度为 6 的木材切割成长度为 1 和 5 的两段,成本为 <code>1 * 5 == 5</code>。现在三段长度分别为 1、5 和 5 的木材可以分别装载到每辆卡车。</p>
37+
</div>
38+
39+
<p><strong class="example">示例 2:</strong></p>
40+
41+
<div class="example-block">
42+
<p><strong>输入:</strong> <span class="example-io">n = 4, m = 4, k = 6</span></p>
43+
44+
<p><strong>输出:</strong> <span class="example-io">0</span></p>
45+
46+
<p><strong>解释:</strong></p>
47+
48+
<p>两根木材已经可以直接装载到卡车上,因此不需要切割。</p>
49+
</div>
50+
51+
<p>&nbsp;</p>
52+
53+
<p><strong>提示:</strong></p>
54+
55+
<ul>
56+
<li><code>2 &lt;= k &lt;= 10<sup>5</sup></code></li>
57+
<li><code>1 &lt;= n, m &lt;= 2 * k</code></li>
58+
<li>输入数据保证木材总存在能被运输的方案。</li>
59+
</ul>
60+
61+
<!-- description:end -->
62+
63+
## 解法
64+
65+
<!-- solution:start -->
66+
67+
### 方法一
68+
69+
<!-- tabs:start -->
70+
71+
#### Python3
72+
73+
```python
74+
75+
```
76+
77+
#### Java
78+
79+
```java
80+
81+
```
82+
83+
#### C++
84+
85+
```cpp
86+
87+
```
88+
89+
#### Go
90+
91+
```go
92+
93+
```
94+
95+
<!-- tabs:end -->
96+
97+
<!-- solution:end -->
98+
99+
<!-- problem:end -->
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3560. Find Minimum Log Transportation Cost](https://leetcode.com/problems/find-minimum-log-transportation-cost)
10+
11+
[中文文档](/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given integers <code>n</code>, <code>m</code>, and <code>k</code>.</p>
18+
19+
<p>There are two logs of lengths <code>n</code> and <code>m</code> units, which need to be transported in three trucks where each truck can carry one log with length <strong>at most</strong> <code>k</code> units.</p>
20+
21+
<p>You may cut the logs into smaller pieces, where the cost of cutting a log of length <code>x</code> into logs of length <code>len1</code> and <code>len2</code> is <code>cost = len1 * len2</code> such that <code>len1 + len2 = x</code>.</p>
22+
23+
<p>Return the <strong>minimum total cost</strong> to distribute the logs onto the trucks. If the logs don&#39;t need to be cut, the total cost is 0.</p>
24+
25+
<p>&nbsp;</p>
26+
<p><strong class="example">Example 1:</strong></p>
27+
28+
<div class="example-block">
29+
<p><strong>Input:</strong> <span class="example-io">n = 6, m = 5, k = 5</span></p>
30+
31+
<p><strong>Output:</strong> <span class="example-io">5</span></p>
32+
33+
<p><strong>Explanation:</strong></p>
34+
35+
<p>Cut the log with length 6 into logs with length 1 and 5, at a cost equal to <code>1 * 5 == 5</code>. Now the three logs of length 1, 5, and 5 can fit in one truck each.</p>
36+
</div>
37+
38+
<p><strong class="example">Example 2:</strong></p>
39+
40+
<div class="example-block">
41+
<p><strong>Input:</strong> <span class="example-io">n = 4, m = 4, k = 6</span></p>
42+
43+
<p><strong>Output:</strong> <span class="example-io">0</span></p>
44+
45+
<p><strong>Explanation:</strong></p>
46+
47+
<p>The two logs can fit in the trucks already, hence we don&#39;t need to cut the logs.</p>
48+
</div>
49+
50+
<p>&nbsp;</p>
51+
<p><strong>Constraints:</strong></p>
52+
53+
<ul>
54+
<li><code>2 &lt;= k &lt;= 10<sup>5</sup></code></li>
55+
<li><code>1 &lt;= n, m &lt;= 2 * k</code></li>
56+
<li>The input is generated such that it is always possible to transport the logs.</li>
57+
</ul>
58+
59+
<!-- description:end -->
60+
61+
## Solutions
62+
63+
<!-- solution:start -->
64+
65+
### Solution 1
66+
67+
<!-- tabs:start -->
68+
69+
#### Python3
70+
71+
```python
72+
73+
```
74+
75+
#### Java
76+
77+
```java
78+
79+
```
80+
81+
#### C++
82+
83+
```cpp
84+
85+
```
86+
87+
#### Go
88+
89+
```go
90+
91+
```
92+
93+
<!-- tabs:end -->
94+
95+
<!-- solution:end -->
96+
97+
<!-- problem:end -->
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3561.Resulting%20String%20After%20Adjacent%20Removals/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3561. 移除相邻字符](https://leetcode.cn/problems/resulting-string-after-adjacent-removals)
10+
11+
[English Version](/solution/3500-3599/3561.Resulting%20String%20After%20Adjacent%20Removals/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个由小写英文字母组成的字符串 <code>s</code>。</p>
18+
19+
<p>你&nbsp;<strong>必须&nbsp;</strong>在字符串 <code>s</code> 中至少存在两个&nbsp;<strong>连续&nbsp;</strong>字符时,反复执行以下操作:</p>
20+
21+
<ul>
22+
<li>移除字符串中&nbsp;<strong>最左边&nbsp;</strong>的一对按照字母表&nbsp;<strong>连续&nbsp;</strong>的相邻字符(无论是按顺序还是逆序,例如 <code>'a'</code> 和 <code>'b'</code>,或 <code>'b'</code> 和 <code>'a'</code>)。</li>
23+
<li>将剩余字符向左移动以填补空隙。</li>
24+
</ul>
25+
26+
<p>当无法再执行任何操作时,返回最终的字符串。</p>
27+
28+
<p><strong>注意:</strong>字母表是循环的,因此 <code>'a'</code> 和 <code>'z'</code> 也视为连续。</p>
29+
30+
<p>&nbsp;</p>
31+
32+
<p><strong class="example">示例 1:</strong></p>
33+
34+
<div class="example-block">
35+
<p><strong>输入:</strong> <span class="example-io">s = "abc"</span></p>
36+
37+
<p><strong>输出:</strong> <span class="example-io">"c"</span></p>
38+
39+
<p><strong>解释:</strong></p>
40+
41+
<ul>
42+
<li>从字符串中移除 <code>"ab"</code>,剩下 <code>"c"</code>。</li>
43+
<li>无法进行进一步操作。因此,所有可能移除操作后的最终字符串为 <code>"c"</code>。</li>
44+
</ul>
45+
</div>
46+
47+
<p><strong class="example">示例 2:</strong></p>
48+
49+
<div class="example-block">
50+
<p><strong>输入:</strong> <span class="example-io">s = "adcb"</span></p>
51+
52+
<p><strong>输出:</strong> <span class="example-io">""</span></p>
53+
54+
<p><strong>解释:</strong></p>
55+
56+
<ul>
57+
<li>从字符串中移除 <code>"dc"</code>,剩下 <code>"ab"</code>。</li>
58+
<li>从字符串中移除 <code>"ab"</code>,剩下 <code>""</code>。</li>
59+
<li>无法进行进一步操作。因此,所有可能移除操作后的最终字符串为 <code>""</code>。</li>
60+
</ul>
61+
</div>
62+
63+
<p><strong class="example">示例 3:</strong></p>
64+
65+
<div class="example-block">
66+
<p><strong>输入:</strong> <span class="example-io">s = "zadb"</span></p>
67+
68+
<p><strong>输出:</strong> <span class="example-io">"db"</span></p>
69+
70+
<p><strong>解释:</strong></p>
71+
72+
<ul>
73+
<li>从字符串中移除 <code>"za"</code>,剩下 <code>"db"</code>。</li>
74+
<li>无法进行进一步操作。因此,所有可能移除操作后的最终字符串为 <code>"db"</code>。</li>
75+
</ul>
76+
</div>
77+
78+
<p>&nbsp;</p>
79+
80+
<p><strong>提示:</strong></p>
81+
82+
<ul>
83+
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
84+
<li><code>s</code> 仅由小写英文字母组成。</li>
85+
</ul>
86+
87+
<!-- description:end -->
88+
89+
## 解法
90+
91+
<!-- solution:start -->
92+
93+
### 方法一
94+
95+
<!-- tabs:start -->
96+
97+
#### Python3
98+
99+
```python
100+
101+
```
102+
103+
#### Java
104+
105+
```java
106+
107+
```
108+
109+
#### C++
110+
111+
```cpp
112+
113+
```
114+
115+
#### Go
116+
117+
```go
118+
119+
```
120+
121+
<!-- tabs:end -->
122+
123+
<!-- solution:end -->
124+
125+
<!-- problem:end -->

0 commit comments

Comments
 (0)