Skip to content

feat: add weekly contest 451 #4431

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
May 25, 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
@@ -0,0 +1,99 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README.md
---

<!-- problem:start -->

# [3560. 木材运输的最小成本](https://leetcode.cn/problems/find-minimum-log-transportation-cost)

[English Version](/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你三个整数 <code>n</code>、<code>m</code> 和 <code>k</code>。</p>

<p>有两根长度分别为 <code>n</code> 和 <code>m</code> 单位的木材,需要通过三辆卡车运输。每辆卡车最多只能装载一根长度&nbsp;<strong>不超过</strong> <code>k</code> 单位的木材。</p>

<p>你可以将木材切成更小的段,其中将长度为 <code>x</code> 的木材切割成长度为 <code>len1</code> 和 <code>len2</code> 的段的成本为 <code>cost = len1 * len2</code>,并且满足 <code>len1 + len2 = x</code>。</p>

<p>返回将木材分配到卡车上的&nbsp;<strong>最小总成本&nbsp;</strong>。如果木材不需要切割,总成本为 0。</p>

<p>&nbsp;</p>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 6, m = 5, k = 5</span></p>

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

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

<p>将长度为 6 的木材切割成长度为 1 和 5 的两段,成本为 <code>1 * 5 == 5</code>。现在三段长度分别为 1、5 和 5 的木材可以分别装载到每辆卡车。</p>
</div>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">n = 4, m = 4, k = 6</span></p>

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

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

<p>两根木材已经可以直接装载到卡车上,因此不需要切割。</p>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>2 &lt;= k &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= n, m &lt;= 2 * k</code></li>
<li>输入数据保证木材总存在能被运输的方案。</li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
---
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README_EN.md
---

<!-- problem:start -->

# [3560. Find Minimum Log Transportation Cost](https://leetcode.com/problems/find-minimum-log-transportation-cost)

[中文文档](/solution/3500-3599/3560.Find%20Minimum%20Log%20Transportation%20Cost/README.md)

## Description

<!-- description:start -->

<p>You are given integers <code>n</code>, <code>m</code>, and <code>k</code>.</p>

<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>

<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>

<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>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 6, m = 5, k = 5</span></p>

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

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

<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>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 4, m = 4, k = 6</span></p>

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

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

<p>The two logs can fit in the trucks already, hence we don&#39;t need to cut the logs.</p>
</div>

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

<ul>
<li><code>2 &lt;= k &lt;= 10<sup>5</sup></code></li>
<li><code>1 &lt;= n, m &lt;= 2 * k</code></li>
<li>The input is generated such that it is always possible to transport the logs.</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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3500-3599/3561.Resulting%20String%20After%20Adjacent%20Removals/README.md
---

<!-- problem:start -->

# [3561. 移除相邻字符](https://leetcode.cn/problems/resulting-string-after-adjacent-removals)

[English Version](/solution/3500-3599/3561.Resulting%20String%20After%20Adjacent%20Removals/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个由小写英文字母组成的字符串 <code>s</code>。</p>

<p>你&nbsp;<strong>必须&nbsp;</strong>在字符串 <code>s</code> 中至少存在两个&nbsp;<strong>连续&nbsp;</strong>字符时,反复执行以下操作:</p>

<ul>
<li>移除字符串中&nbsp;<strong>最左边&nbsp;</strong>的一对按照字母表&nbsp;<strong>连续&nbsp;</strong>的相邻字符(无论是按顺序还是逆序,例如 <code>'a'</code> 和 <code>'b'</code>,或 <code>'b'</code> 和 <code>'a'</code>)。</li>
<li>将剩余字符向左移动以填补空隙。</li>
</ul>

<p>当无法再执行任何操作时,返回最终的字符串。</p>

<p><strong>注意:</strong>字母表是循环的,因此 <code>'a'</code> 和 <code>'z'</code> 也视为连续。</p>

<p>&nbsp;</p>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "abc"</span></p>

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

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

<ul>
<li>从字符串中移除 <code>"ab"</code>,剩下 <code>"c"</code>。</li>
<li>无法进行进一步操作。因此,所有可能移除操作后的最终字符串为 <code>"c"</code>。</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "adcb"</span></p>

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

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

<ul>
<li>从字符串中移除 <code>"dc"</code>,剩下 <code>"ab"</code>。</li>
<li>从字符串中移除 <code>"ab"</code>,剩下 <code>""</code>。</li>
<li>无法进行进一步操作。因此,所有可能移除操作后的最终字符串为 <code>""</code>。</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>输入:</strong> <span class="example-io">s = "zadb"</span></p>

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

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

<ul>
<li>从字符串中移除 <code>"za"</code>,剩下 <code>"db"</code>。</li>
<li>无法进行进一步操作。因此,所有可能移除操作后的最终字符串为 <code>"db"</code>。</li>
</ul>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= s.length &lt;= 10<sup>5</sup></code></li>
<li><code>s</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