Skip to content

feat: add biweekly contest 160 #4551

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 1 commit into from
Jul 6, 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,105 @@
---
comments: true
difficulty: 简单
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README.md
---

<!-- problem:start -->

# [3602. 十六进制和三十六进制转化](https://leetcode.cn/problems/hexadecimal-and-hexatrigesimal-conversion)

[English Version](/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你一个整数 <code>n</code>。</p>

<p>返回 <code>n<sup>2</sup></code> 的&nbsp;<strong>十六进制表示</strong> 和 <code>n<sup>3</sup></code> 的&nbsp;<strong>三十六进制表示</strong> 拼接成的字符串。</p>

<p><strong>十六进制&nbsp;</strong>数定义为使用数字 <code>0 – 9</code> 和大写字母 <code>A - F</code> 表示 0 到 15 的值。</p>

<p><strong>三十六进制&nbsp;</strong>数定义为使用数字 <code>0 – 9</code> 和大写字母 <code>A - Z</code> 表示 0 到 35 的值。</p>

<p>&nbsp;</p>

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

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

<p><strong>输出:&nbsp;</strong><span class="example-io">"A91P1"</span></p>

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

<ul>
<li><code>n<sup>2</sup> = 13 * 13 = 169</code>。在十六进制中,它转换为 <code>(10 * 16) + 9 = 169</code>,对应于 <code>"A9"</code>。</li>
<li><code>n<sup>3</sup> = 13 * 13 * 13 = 2197</code>。在三十六进制中,它转换为 <code>(1 * 36<sup>2</sup>) + (25 * 36) + 1 = 2197</code>,对应于 <code>"1P1"</code>。</li>
<li>连接两个结果得到 <code>"A9" + "1P1" = "A91P1"</code>。</li>
</ul>
</div>

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

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

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

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

<ul>
<li><code>n<sup>2</sup> = 36 * 36 = 1296</code>。在十六进制中,它转换为 <code>(5 * 16<sup>2</sup>) + (1 * 16) + 0 = 1296</code>,对应于 <code>"510"</code>。</li>
<li><code>n<sup>3</sup> = 36 * 36 * 36 = 46656</code>。在三十六进制中,它转换为 <code>(1 * 36<sup>3</sup>) + (0 * 36<sup>2</sup>) + (0 * 36) + 0 = 46656</code>,对应于 <code>"1000"</code>。</li>
<li>连接两个结果得到 <code>"510" + "1000" = "5101000"</code>。</li>
</ul>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= n &lt;= 1000</code></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,103 @@
---
comments: true
difficulty: Easy
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README_EN.md
---

<!-- problem:start -->

# [3602. Hexadecimal and Hexatrigesimal Conversion](https://leetcode.com/problems/hexadecimal-and-hexatrigesimal-conversion)

[中文文档](/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README.md)

## Description

<!-- description:start -->

<p>You are given an integer <code>n</code>.</p>

<p>Return the concatenation of the <strong>hexadecimal</strong> representation of <code>n<sup>2</sup></code> and the <strong>hexatrigesimal</strong> representation of <code>n<sup>3</sup></code>.</p>

<p>A <strong>hexadecimal</strong> number is defined as a base-16 numeral system that uses the digits <code>0 &ndash; 9</code> and the uppercase letters <code>A - F</code> to represent values from 0 to 15.</p>

<p>A <strong>hexatrigesimal</strong> number is defined as a base-36 numeral system that uses the digits <code>0 &ndash; 9</code> and the uppercase letters <code>A - Z</code> to represent values from 0 to 35.</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 = 13</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;A91P1&quot;</span></p>

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

<ul>
<li><code>n<sup>2</sup> = 13 * 13 = 169</code>. In hexadecimal, it converts to <code>(10 * 16) + 9 = 169</code>, which corresponds to <code>&quot;A9&quot;</code>.</li>
<li><code>n<sup>3</sup> = 13 * 13 * 13 = 2197</code>. In hexatrigesimal, it converts to <code>(1 * 36<sup>2</sup>) + (25 * 36) + 1 = 2197</code>, which corresponds to <code>&quot;1P1&quot;</code>.</li>
<li>Concatenating both results gives <code>&quot;A9&quot; + &quot;1P1&quot; = &quot;A91P1&quot;</code>.</li>
</ul>
</div>

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

<div class="example-block">
<p><strong>Input:</strong> <span class="example-io">n = 36</span></p>

<p><strong>Output:</strong> <span class="example-io">&quot;5101000&quot;</span></p>

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

<ul>
<li><code>n<sup>2</sup> = 36 * 36 = 1296</code>. In hexadecimal, it converts to <code>(5 * 16<sup>2</sup>) + (1 * 16) + 0 = 1296</code>, which corresponds to <code>&quot;510&quot;</code>.</li>
<li><code>n<sup>3</sup> = 36 * 36 * 36 = 46656</code>. In hexatrigesimal, it converts to <code>(1 * 36<sup>3</sup>) + (0 * 36<sup>2</sup>) + (0 * 36) + 0 = 46656</code>, which corresponds to <code>&quot;1000&quot;</code>.</li>
<li>Concatenating both results gives <code>&quot;510&quot; + &quot;1000&quot; = &quot;5101000&quot;</code>.</li>
</ul>
</div>

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

<ul>
<li><code>1 &lt;= n &lt;= 1000</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 -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
---
comments: true
difficulty: 中等
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3603.Minimum%20Cost%20Path%20with%20Alternating%20Directions%20II/README.md
---

<!-- problem:start -->

# [3603. 交替方向的最小路径代价 II](https://leetcode.cn/problems/minimum-cost-path-with-alternating-directions-ii)

[English Version](/solution/3600-3699/3603.Minimum%20Cost%20Path%20with%20Alternating%20Directions%20II/README_EN.md)

## 题目描述

<!-- description:start -->

<p>给你两个整数 <code>m</code> 和 <code>n</code>,分别表示网格的行数和列数。</p>

<p>进入单元格 <code>(i, j)</code> 的成本定义为 <code>(i + 1) * (j + 1)</code>。</p>

<p>另外给你一个二维整数数组 <code>waitCost</code>,其中 <code>waitCost[i][j]</code> 定义了在该单元格&nbsp;<strong>等待&nbsp;</strong>的成本。</p>

<p>你从第 1 秒开始在单元格 <code>(0, 0)</code>。</p>

<p>每一步,你都遵循交替模式:</p>

<ul>
<li>在&nbsp;<strong>奇数秒&nbsp;</strong>,你必须向&nbsp;<strong>右&nbsp;</strong>或向&nbsp;<strong>下&nbsp;</strong>移动到&nbsp;<strong>相邻&nbsp;</strong>的单元格,并支付其进入成本。</li>
<li>在&nbsp;<strong>偶数秒&nbsp;</strong>,你必须原地&nbsp;<strong>等待&nbsp;</strong>,并支付 <code>waitCost[i][j]</code>。</li>
</ul>

<p>返回到达 <code>(m - 1, n - 1)</code> 所需的&nbsp;<strong>最小&nbsp;</strong>总成本。</p>

<p>&nbsp;</p>

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

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

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

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

<p>最佳路径为:</p>

<ul>
<li>从第 1 秒开始在单元格 <code>(0, 0)</code>,进入成本为 <code>(0 + 1) * (0 + 1) = 1</code>。</li>
<li><strong>第 1 秒</strong>:向右移动到单元格 <code>(0, 1)</code>,进入成本为 <code>(0 + 1) * (1 + 1) = 2</code>。</li>
</ul>

<p>因此,总成本为 <code>1 + 2 = 3</code>。</p>
</div>

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

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

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

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

<p>最佳路径为:</p>

<ul>
<li>从第 1 秒开始在单元格 <code>(0, 0)</code>,进入成本为 <code>(0 + 1) * (0 + 1) = 1</code>。</li>
<li><strong>第 1 秒</strong>:向下移动到单元格 <code>(1, 0)</code>,进入成本为 <code>(1 + 1) * (0 + 1) = 2</code>。</li>
<li><strong>第 2 秒</strong>:在单元格 <code>(1, 0)</code> 等待,支付 <code>waitCost[1][0] = 2</code>。</li>
<li><strong>第 3 秒</strong>:向右移动到单元格 <code>(1, 1)</code>,进入成本为 <code>(1 + 1) * (1 + 1) = 4</code>。</li>
</ul>

<p>因此,总成本为 <code>1 + 2 + 2 + 4 = 9</code>。</p>
</div>

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

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

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

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

<p>最佳路径为:</p>

<ul>
<li>从第 1 秒开始在单元格 <code>(0, 0)</code>,进入成本为 <code>(0 + 1) * (0 + 1) = 1</code>。</li>
<li><strong>第 1 秒</strong>:向右移动到单元格 <code>(0, 1)</code>,进入成本为 <code>(0 + 1) * (1 + 1) = 2</code>。</li>
<li><strong>第 2 秒</strong>:在单元格 <code>(0, 1)</code> 等待,支付 <code>waitCost[0][1] = 1</code>。</li>
<li><strong>第 3 秒</strong>:向下移动到单元格 <code>(1, 1)</code>,进入成本为 <code>(1 + 1) * (1 + 1) = 4</code>。</li>
<li><strong>第 4 秒</strong>:在单元格 <code>(1, 1)</code> 等待,支付 <code>waitCost[1][1] = 2</code>。</li>
<li><strong>第 5 秒</strong>:向右移动到单元格 <code>(1, 2)</code>,进入成本为 <code>(1 + 1) * (2 + 1) = 6</code>。</li>
</ul>

<p>因此,总成本为 <code>1 + 2 + 1 + 4 + 2 + 6 = 16</code>。</p>
</div>

<p>&nbsp;</p>

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

<ul>
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
<li><code>2 &lt;= m * n &lt;= 10<sup>5</sup></code></li>
<li><code>waitCost.length == m</code></li>
<li><code>waitCost[0].length == n</code></li>
<li><code>0 &lt;= waitCost[i][j] &lt;= 10<sup>5</sup></code></li>
</ul>

<!-- description:end -->

## 解法

<!-- solution:start -->

### 方法一

<!-- tabs:start -->

#### Python3

```python

```

#### Java

```java

```

#### C++

```cpp

```

#### Go

```go

```

<!-- tabs:end -->

<!-- solution:end -->

<!-- problem:end -->
Loading