Skip to content

Commit d78ff5d

Browse files
committed
feat: add biweekly contest 160
1 parent 9ab3cee commit d78ff5d

File tree

16 files changed

+1087
-1
lines changed

16 files changed

+1087
-1
lines changed
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
---
2+
comments: true
3+
difficulty: 简单
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3602. 十六进制和三十六进制转化](https://leetcode.cn/problems/hexadecimal-and-hexatrigesimal-conversion)
10+
11+
[English Version](/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你一个整数 <code>n</code>。</p>
18+
19+
<p>返回 <code>n<sup>2</sup></code> 的&nbsp;<strong>十六进制表示</strong> 和 <code>n<sup>3</sup></code> 的&nbsp;<strong>三十六进制表示</strong> 拼接成的字符串。</p>
20+
21+
<p><strong>十六进制&nbsp;</strong>数定义为使用数字 <code>0 – 9</code> 和大写字母 <code>A - F</code> 表示 0 到 15 的值。</p>
22+
23+
<p><strong>三十六进制&nbsp;</strong>数定义为使用数字 <code>0 – 9</code> 和大写字母 <code>A - Z</code> 表示 0 到 35 的值。</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 = 13</span></p>
31+
32+
<p><strong>输出:&nbsp;</strong><span class="example-io">"A91P1"</span></p>
33+
34+
<p><strong>解释:</strong></p>
35+
36+
<ul>
37+
<li><code>n<sup>2</sup> = 13 * 13 = 169</code>。在十六进制中,它转换为 <code>(10 * 16) + 9 = 169</code>,对应于 <code>"A9"</code>。</li>
38+
<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>
39+
<li>连接两个结果得到 <code>"A9" + "1P1" = "A91P1"</code>。</li>
40+
</ul>
41+
</div>
42+
43+
<p><strong class="example">示例 2:</strong></p>
44+
45+
<div class="example-block">
46+
<p><strong>输入:</strong><span class="example-io">n = 36</span></p>
47+
48+
<p><strong>输出:</strong><span class="example-io">"5101000"</span></p>
49+
50+
<p><strong>解释:</strong></p>
51+
52+
<ul>
53+
<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>
54+
<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>
55+
<li>连接两个结果得到 <code>"510" + "1000" = "5101000"</code>。</li>
56+
</ul>
57+
</div>
58+
59+
<p>&nbsp;</p>
60+
61+
<p><strong>提示:</strong></p>
62+
63+
<ul>
64+
<li><code>1 &lt;= n &lt;= 1000</code></li>
65+
</ul>
66+
67+
<!-- description:end -->
68+
69+
## 解法
70+
71+
<!-- solution:start -->
72+
73+
### 方法一
74+
75+
<!-- tabs:start -->
76+
77+
#### Python3
78+
79+
```python
80+
81+
```
82+
83+
#### Java
84+
85+
```java
86+
87+
```
88+
89+
#### C++
90+
91+
```cpp
92+
93+
```
94+
95+
#### Go
96+
97+
```go
98+
99+
```
100+
101+
<!-- tabs:end -->
102+
103+
<!-- solution:end -->
104+
105+
<!-- problem:end -->
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
---
2+
comments: true
3+
difficulty: Easy
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README_EN.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3602. Hexadecimal and Hexatrigesimal Conversion](https://leetcode.com/problems/hexadecimal-and-hexatrigesimal-conversion)
10+
11+
[中文文档](/solution/3600-3699/3602.Hexadecimal%20and%20Hexatrigesimal%20Conversion/README.md)
12+
13+
## Description
14+
15+
<!-- description:start -->
16+
17+
<p>You are given an integer <code>n</code>.</p>
18+
19+
<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>
20+
21+
<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>
22+
23+
<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>
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 = 13</span></p>
30+
31+
<p><strong>Output:</strong> <span class="example-io">&quot;A91P1&quot;</span></p>
32+
33+
<p><strong>Explanation:</strong></p>
34+
35+
<ul>
36+
<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>
37+
<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>
38+
<li>Concatenating both results gives <code>&quot;A9&quot; + &quot;1P1&quot; = &quot;A91P1&quot;</code>.</li>
39+
</ul>
40+
</div>
41+
42+
<p><strong class="example">Example 2:</strong></p>
43+
44+
<div class="example-block">
45+
<p><strong>Input:</strong> <span class="example-io">n = 36</span></p>
46+
47+
<p><strong>Output:</strong> <span class="example-io">&quot;5101000&quot;</span></p>
48+
49+
<p><strong>Explanation:</strong></p>
50+
51+
<ul>
52+
<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>
53+
<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>
54+
<li>Concatenating both results gives <code>&quot;510&quot; + &quot;1000&quot; = &quot;5101000&quot;</code>.</li>
55+
</ul>
56+
</div>
57+
58+
<p>&nbsp;</p>
59+
<p><strong>Constraints:</strong></p>
60+
61+
<ul>
62+
<li><code>1 &lt;= n &lt;= 1000</code></li>
63+
</ul>
64+
65+
<!-- description:end -->
66+
67+
## Solutions
68+
69+
<!-- solution:start -->
70+
71+
### Solution 1
72+
73+
<!-- tabs:start -->
74+
75+
#### Python3
76+
77+
```python
78+
79+
```
80+
81+
#### Java
82+
83+
```java
84+
85+
```
86+
87+
#### C++
88+
89+
```cpp
90+
91+
```
92+
93+
#### Go
94+
95+
```go
96+
97+
```
98+
99+
<!-- tabs:end -->
100+
101+
<!-- solution:end -->
102+
103+
<!-- problem:end -->
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
---
2+
comments: true
3+
difficulty: 中等
4+
edit_url: https://github.com/doocs/leetcode/edit/main/solution/3600-3699/3603.Minimum%20Cost%20Path%20with%20Alternating%20Directions%20II/README.md
5+
---
6+
7+
<!-- problem:start -->
8+
9+
# [3603. 交替方向的最小路径代价 II](https://leetcode.cn/problems/minimum-cost-path-with-alternating-directions-ii)
10+
11+
[English Version](/solution/3600-3699/3603.Minimum%20Cost%20Path%20with%20Alternating%20Directions%20II/README_EN.md)
12+
13+
## 题目描述
14+
15+
<!-- description:start -->
16+
17+
<p>给你两个整数 <code>m</code> 和 <code>n</code>,分别表示网格的行数和列数。</p>
18+
19+
<p>进入单元格 <code>(i, j)</code> 的成本定义为 <code>(i + 1) * (j + 1)</code>。</p>
20+
21+
<p>另外给你一个二维整数数组 <code>waitCost</code>,其中 <code>waitCost[i][j]</code> 定义了在该单元格&nbsp;<strong>等待&nbsp;</strong>的成本。</p>
22+
23+
<p>你从第 1 秒开始在单元格 <code>(0, 0)</code>。</p>
24+
25+
<p>每一步,你都遵循交替模式:</p>
26+
27+
<ul>
28+
<li>在&nbsp;<strong>奇数秒&nbsp;</strong>,你必须向&nbsp;<strong>右&nbsp;</strong>或向&nbsp;<strong>下&nbsp;</strong>移动到&nbsp;<strong>相邻&nbsp;</strong>的单元格,并支付其进入成本。</li>
29+
<li>在&nbsp;<strong>偶数秒&nbsp;</strong>,你必须原地&nbsp;<strong>等待&nbsp;</strong>,并支付 <code>waitCost[i][j]</code>。</li>
30+
</ul>
31+
32+
<p>返回到达 <code>(m - 1, n - 1)</code> 所需的&nbsp;<strong>最小&nbsp;</strong>总成本。</p>
33+
34+
<p>&nbsp;</p>
35+
36+
<p><strong class="example">示例 1:</strong></p>
37+
38+
<div class="example-block">
39+
<p><strong>输入:</strong><span class="example-io">m = 1, n = 2, waitCost = [[1,2]]</span></p>
40+
41+
<p><strong>输出:</strong><span class="example-io">3</span></p>
42+
43+
<p><strong>解释:</strong></p>
44+
45+
<p>最佳路径为:</p>
46+
47+
<ul>
48+
<li>从第 1 秒开始在单元格 <code>(0, 0)</code>,进入成本为 <code>(0 + 1) * (0 + 1) = 1</code>。</li>
49+
<li><strong>第 1 秒</strong>:向右移动到单元格 <code>(0, 1)</code>,进入成本为 <code>(0 + 1) * (1 + 1) = 2</code>。</li>
50+
</ul>
51+
52+
<p>因此,总成本为 <code>1 + 2 = 3</code>。</p>
53+
</div>
54+
55+
<p><strong class="example">示例 2:</strong></p>
56+
57+
<div class="example-block">
58+
<p><strong>输入:</strong><span class="example-io">m = 2, n = 2, waitCost = [[3,5],[2,4]]</span></p>
59+
60+
<p><strong>输出:</strong><span class="example-io">9</span></p>
61+
62+
<p><strong>解释:</strong></p>
63+
64+
<p>最佳路径为:</p>
65+
66+
<ul>
67+
<li>从第 1 秒开始在单元格 <code>(0, 0)</code>,进入成本为 <code>(0 + 1) * (0 + 1) = 1</code>。</li>
68+
<li><strong>第 1 秒</strong>:向下移动到单元格 <code>(1, 0)</code>,进入成本为 <code>(1 + 1) * (0 + 1) = 2</code>。</li>
69+
<li><strong>第 2 秒</strong>:在单元格 <code>(1, 0)</code> 等待,支付 <code>waitCost[1][0] = 2</code>。</li>
70+
<li><strong>第 3 秒</strong>:向右移动到单元格 <code>(1, 1)</code>,进入成本为 <code>(1 + 1) * (1 + 1) = 4</code>。</li>
71+
</ul>
72+
73+
<p>因此,总成本为 <code>1 + 2 + 2 + 4 = 9</code>。</p>
74+
</div>
75+
76+
<p><strong class="example">示例 3:</strong></p>
77+
78+
<div class="example-block">
79+
<p><strong>输入:</strong><span class="example-io">m = 2, n = 3, waitCost = [[6,1,4],[3,2,5]]</span></p>
80+
81+
<p><strong>输出:</strong><span class="example-io">16</span></p>
82+
83+
<p><strong>解释:</strong></p>
84+
85+
<p>最佳路径为:</p>
86+
87+
<ul>
88+
<li>从第 1 秒开始在单元格 <code>(0, 0)</code>,进入成本为 <code>(0 + 1) * (0 + 1) = 1</code>。</li>
89+
<li><strong>第 1 秒</strong>:向右移动到单元格 <code>(0, 1)</code>,进入成本为 <code>(0 + 1) * (1 + 1) = 2</code>。</li>
90+
<li><strong>第 2 秒</strong>:在单元格 <code>(0, 1)</code> 等待,支付 <code>waitCost[0][1] = 1</code>。</li>
91+
<li><strong>第 3 秒</strong>:向下移动到单元格 <code>(1, 1)</code>,进入成本为 <code>(1 + 1) * (1 + 1) = 4</code>。</li>
92+
<li><strong>第 4 秒</strong>:在单元格 <code>(1, 1)</code> 等待,支付 <code>waitCost[1][1] = 2</code>。</li>
93+
<li><strong>第 5 秒</strong>:向右移动到单元格 <code>(1, 2)</code>,进入成本为 <code>(1 + 1) * (2 + 1) = 6</code>。</li>
94+
</ul>
95+
96+
<p>因此,总成本为 <code>1 + 2 + 1 + 4 + 2 + 6 = 16</code>。</p>
97+
</div>
98+
99+
<p>&nbsp;</p>
100+
101+
<p><strong>提示:</strong></p>
102+
103+
<ul>
104+
<li><code>1 &lt;= m, n &lt;= 10<sup>5</sup></code></li>
105+
<li><code>2 &lt;= m * n &lt;= 10<sup>5</sup></code></li>
106+
<li><code>waitCost.length == m</code></li>
107+
<li><code>waitCost[0].length == n</code></li>
108+
<li><code>0 &lt;= waitCost[i][j] &lt;= 10<sup>5</sup></code></li>
109+
</ul>
110+
111+
<!-- description:end -->
112+
113+
## 解法
114+
115+
<!-- solution:start -->
116+
117+
### 方法一
118+
119+
<!-- tabs:start -->
120+
121+
#### Python3
122+
123+
```python
124+
125+
```
126+
127+
#### Java
128+
129+
```java
130+
131+
```
132+
133+
#### C++
134+
135+
```cpp
136+
137+
```
138+
139+
#### Go
140+
141+
```go
142+
143+
```
144+
145+
<!-- tabs:end -->
146+
147+
<!-- solution:end -->
148+
149+
<!-- problem:end -->

0 commit comments

Comments
 (0)