Skip to content

Commit a4b8b4e

Browse files
authored
feat: add weekly contest 379 (#2191)
1 parent 07290a1 commit a4b8b4e

File tree

16 files changed

+796
-0
lines changed

16 files changed

+796
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# [10035. 对角线最长的矩形的面积](https://leetcode.cn/problems/maximum-area-of-longest-diagonal-rectangle)
2+
3+
[English Version](/solution/10000-10099/10035.Maximum%20Area%20of%20Longest%20Diagonal%20Rectangle/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从<strong> 0</strong> 开始的二维整数数组 <code>dimensions</code>。</p>
10+
11+
<p>对于所有下标 <code>i</code>(<code>0 &lt;= i &lt; dimensions.length</code>),<code>dimensions[i][0]</code> 表示矩形 <span style="font-size: 13.3333px;"> <code>i</code></span> 的长度,而 <code>dimensions[i][1]</code> 表示矩形 <span style="font-size: 13.3333px;"> <code>i</code></span> 的宽度。</p>
12+
13+
<p>返回对角线最 <strong>长 </strong>的矩形的<strong> 面积 </strong>。如果存在多个对角线长度相同的矩形,返回面积最<strong> 大 </strong>的矩形的面积。</p>
14+
15+
<p>&nbsp;</p>
16+
17+
<p><strong class="example">示例 1:</strong></p>
18+
19+
<pre>
20+
<strong>输入:</strong>dimensions = [[9,3],[8,6]]
21+
<strong>输出:</strong>48
22+
<strong>解释:</strong>
23+
下标 = 0,长度 = 9,宽度 = 3。对角线长度 = sqrt(9 * 9 + 3 * 3) = sqrt(90) ≈<!-- notionvc: 882cf44c-3b17-428e-9c65-9940810216f1 --> 9.487。
24+
下标 = 1,长度 = 8,宽度 = 6。对角线长度 = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10。
25+
因此,下标为 1 的矩形对角线更长,所以返回面积 = 8 * 6 = 48。
26+
</pre>
27+
28+
<p><strong class="example">示例 2:</strong></p>
29+
30+
<pre>
31+
<strong>输入:</strong>dimensions = [[3,4],[4,3]]
32+
<strong>输出:</strong>12
33+
<strong>解释:</strong>两个矩形的对角线长度相同,为 5,所以最大面积 = 12。
34+
</pre>
35+
36+
<p>&nbsp;</p>
37+
38+
<p><strong>提示:</strong></p>
39+
40+
<ul>
41+
<li><code>1 &lt;= dimensions.length &lt;= 100</code></li>
42+
<li><code>dimensions[i].length == 2</code></li>
43+
<li><code>1 &lt;= dimensions[i][0], dimensions[i][1] &lt;= 100</code></li>
44+
</ul>
45+
46+
## 解法
47+
48+
<!-- 这里可写通用的实现逻辑 -->
49+
50+
<!-- tabs:start -->
51+
52+
### **Python3**
53+
54+
<!-- 这里可写当前语言的特殊实现逻辑 -->
55+
56+
```python
57+
58+
```
59+
60+
### **Java**
61+
62+
<!-- 这里可写当前语言的特殊实现逻辑 -->
63+
64+
```java
65+
66+
```
67+
68+
### **C++**
69+
70+
```cpp
71+
72+
```
73+
74+
### **Go**
75+
76+
```go
77+
78+
```
79+
80+
### **...**
81+
82+
```
83+
84+
```
85+
86+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
# [10035. Maximum Area of Longest Diagonal Rectangle](https://leetcode.com/problems/maximum-area-of-longest-diagonal-rectangle)
2+
3+
[中文文档](/solution/10000-10099/10035.Maximum%20Area%20of%20Longest%20Diagonal%20Rectangle/README.md)
4+
5+
## Description
6+
7+
<p>You are given a 2D <strong>0-indexed </strong>integer array <code>dimensions</code>.</p>
8+
9+
<p>For all indices <code>i</code>, <code>0 &lt;= i &lt; dimensions.length</code>, <code>dimensions[i][0]</code> represents the length and <code>dimensions[i][1]</code> represents the width of the rectangle<span style="font-size: 13.3333px;"> <code>i</code></span>.</p>
10+
11+
<p>Return <em>the <strong>area</strong> of the rectangle having the <strong>longest</strong> diagonal. If there are multiple rectangles with the longest diagonal, return the area of the rectangle having the <strong>maximum</strong> area.</em></p>
12+
13+
<p>&nbsp;</p>
14+
<p><strong class="example">Example 1:</strong></p>
15+
16+
<pre>
17+
<strong>Input:</strong> dimensions = [[9,3],[8,6]]
18+
<strong>Output:</strong> 48
19+
<strong>Explanation:</strong>
20+
For index = 0, length = 9 and width = 3. Diagonal length = sqrt(9 * 9 + 3 * 3) = sqrt(90) &asymp;<!-- notionvc: 882cf44c-3b17-428e-9c65-9940810216f1 --> 9.487.
21+
For index = 1, length = 8 and width = 6. Diagonal length = sqrt(8 * 8 + 6 * 6) = sqrt(100) = 10.
22+
So, the rectangle at index 1 has a greater diagonal length therefore we return area = 8 * 6 = 48.
23+
</pre>
24+
25+
<p><strong class="example">Example 2:</strong></p>
26+
27+
<pre>
28+
<strong>Input:</strong> dimensions = [[3,4],[4,3]]
29+
<strong>Output:</strong> 12
30+
<strong>Explanation:</strong> Length of diagonal is the same for both which is 5, so maximum area = 12.
31+
</pre>
32+
33+
<p>&nbsp;</p>
34+
<p><strong>Constraints:</strong></p>
35+
36+
<ul>
37+
<li><code>1 &lt;= dimensions.length &lt;= 100</code></li>
38+
<li><code><font face="monospace">dimensions[i].length == 2</font></code></li>
39+
<li><code><font face="monospace">1 &lt;= dimensions[i][0], dimensions[i][1] &lt;= 100</font></code></li>
40+
</ul>
41+
42+
## Solutions
43+
44+
<!-- tabs:start -->
45+
46+
### **Python3**
47+
48+
```python
49+
50+
```
51+
52+
### **Java**
53+
54+
```java
55+
56+
```
57+
58+
### **C++**
59+
60+
```cpp
61+
62+
```
63+
64+
### **Go**
65+
66+
```go
67+
68+
```
69+
70+
### **...**
71+
72+
```
73+
74+
```
75+
76+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
# [10036. 捕获黑皇后需要的最少移动次数](https://leetcode.cn/problems/minimum-moves-to-capture-the-queen)
2+
3+
[English Version](/solution/10000-10099/10036.Minimum%20Moves%20to%20Capture%20The%20Queen/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>现有一个下标从 <strong>0</strong> 开始的 <code>8 x 8</code> 棋盘,上面有 <code>3</code> 枚棋子。</p>
10+
11+
<p>给你 <code>6</code> 个整数 <code>a</code> 、<code>b</code> 、<code>c</code> 、<code>d</code> 、<code>e</code> 和 <code>f</code> ,其中:</p>
12+
13+
<ul>
14+
<li><code>(a, b)</code> 表示白色车的位置。</li>
15+
<li><code>(c, d)</code> 表示白色象的位置。</li>
16+
<li><code>(e, f)</code> 表示黑皇后的位置。</li>
17+
</ul>
18+
19+
<p>假定你只能移动白色棋子,返回捕获黑皇后所需的<strong>最少</strong>移动次数。</p>
20+
21+
<p><strong>请注意</strong>:</p>
22+
23+
<ul>
24+
<li>车可以向垂直或水平方向移动任意数量的格子,但不能跳过其他棋子。</li>
25+
<li>象可以沿对角线方向移动任意数量的格子,但不能跳过其他棋子。</li>
26+
<li>如果车或象能移向皇后所在的格子,则认为它们可以捕获皇后。</li>
27+
<li>皇后不能移动。</li>
28+
</ul>
29+
30+
<p>&nbsp;</p>
31+
32+
<p><strong class="example">示例 1:</strong></p>
33+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/10000-10099/10036.Minimum%20Moves%20to%20Capture%20The%20Queen/images//ex1.png" style="width: 600px; height: 600px; padding: 10px; background: #fff; border-radius: .5rem;" />
34+
<pre>
35+
<strong>输入:</strong>a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
36+
<strong>输出:</strong>2
37+
<strong>解释:</strong>将白色车先移动到 (1, 3) ,然后移动到 (2, 3) 来捕获黑皇后,共需移动 2 次。
38+
由于起始时没有任何棋子正在攻击黑皇后,要想捕获黑皇后,移动次数不可能少于 2 次。
39+
</pre>
40+
41+
<p><strong class="example">示例 2:</strong></p>
42+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/10000-10099/10036.Minimum%20Moves%20to%20Capture%20The%20Queen/images//ex2.png" style="width: 600px; height: 600px;padding: 10px; background: #fff; border-radius: .5rem;" />
43+
<pre>
44+
<strong>输入:</strong>a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
45+
<strong>输出:</strong>1
46+
<strong>解释:</strong>可以通过以下任一方式移动 1 次捕获黑皇后:
47+
- 将白色车移动到 (5, 2) 。
48+
- 将白色象移动到 (5, 2) 。
49+
</pre>
50+
51+
<p>&nbsp;</p>
52+
53+
<p><strong>提示:</strong></p>
54+
55+
<ul>
56+
<li><code>1 &lt;= a, b, c, d, e, f &lt;= 8</code></li>
57+
<li>两枚棋子不会同时出现在同一个格子上。</li>
58+
</ul>
59+
60+
## 解法
61+
62+
<!-- 这里可写通用的实现逻辑 -->
63+
64+
<!-- tabs:start -->
65+
66+
### **Python3**
67+
68+
<!-- 这里可写当前语言的特殊实现逻辑 -->
69+
70+
```python
71+
72+
```
73+
74+
### **Java**
75+
76+
<!-- 这里可写当前语言的特殊实现逻辑 -->
77+
78+
```java
79+
80+
```
81+
82+
### **C++**
83+
84+
```cpp
85+
86+
```
87+
88+
### **Go**
89+
90+
```go
91+
92+
```
93+
94+
### **...**
95+
96+
```
97+
98+
```
99+
100+
<!-- tabs:end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
# [10036. Minimum Moves to Capture The Queen](https://leetcode.com/problems/minimum-moves-to-capture-the-queen)
2+
3+
[中文文档](/solution/10000-10099/10036.Minimum%20Moves%20to%20Capture%20The%20Queen/README.md)
4+
5+
## Description
6+
7+
<p>There is a <strong>1-indexed</strong> <code>8 x 8</code> chessboard containing <code>3</code> pieces.</p>
8+
9+
<p>You are given <code>6</code> integers <code>a</code>, <code>b</code>, <code>c</code>, <code>d</code>, <code>e</code>, and <code>f</code> where:</p>
10+
11+
<ul>
12+
<li><code>(a, b)</code> denotes the position of the white rook.</li>
13+
<li><code>(c, d)</code> denotes the position of the white bishop.</li>
14+
<li><code>(e, f)</code> denotes the position of the black queen.</li>
15+
</ul>
16+
17+
<p>Given that you can only move the white pieces, return <em>the <strong>minimum</strong> number of moves required to capture the black queen</em>.</p>
18+
19+
<p><strong>Note</strong> that:</p>
20+
21+
<ul>
22+
<li>Rooks can move any number of squares either vertically or horizontally, but cannot jump over other pieces.</li>
23+
<li>Bishops can move any number of squares diagonally, but cannot jump over other pieces.</li>
24+
<li>A rook or a bishop can capture the queen if it is located in a square that they can move to.</li>
25+
<li>The queen does not move.</li>
26+
</ul>
27+
28+
<p>&nbsp;</p>
29+
<p><strong class="example">Example 1:</strong></p>
30+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/10000-10099/10036.Minimum%20Moves%20to%20Capture%20The%20Queen/images//ex1.png" style="width: 600px; height: 600px; padding: 10px; background: #fff; border-radius: .5rem;" />
31+
<pre>
32+
<strong>Input:</strong> a = 1, b = 1, c = 8, d = 8, e = 2, f = 3
33+
<strong>Output:</strong> 2
34+
<strong>Explanation:</strong> We can capture the black queen in two moves by moving the white rook to (1, 3) then to (2, 3).
35+
It is impossible to capture the black queen in less than two moves since it is not being attacked by any of the pieces at the beginning.
36+
</pre>
37+
38+
<p><strong class="example">Example 2:</strong></p>
39+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/10000-10099/10036.Minimum%20Moves%20to%20Capture%20The%20Queen/images//ex2.png" style="width: 600px; height: 600px;padding: 10px; background: #fff; border-radius: .5rem;" />
40+
<pre>
41+
<strong>Input:</strong> a = 5, b = 3, c = 3, d = 4, e = 5, f = 2
42+
<strong>Output:</strong> 1
43+
<strong>Explanation:</strong> We can capture the black queen in a single move by doing one of the following:
44+
- Move the white rook to (5, 2).
45+
- Move the white bishop to (5, 2).
46+
</pre>
47+
48+
<p>&nbsp;</p>
49+
<p><strong>Constraints:</strong></p>
50+
51+
<ul>
52+
<li><code>1 &lt;= a, b, c, d, e, f &lt;= 8</code></li>
53+
<li>No two pieces are on the same square.</li>
54+
</ul>
55+
56+
## Solutions
57+
58+
<!-- tabs:start -->
59+
60+
### **Python3**
61+
62+
```python
63+
64+
```
65+
66+
### **Java**
67+
68+
```java
69+
70+
```
71+
72+
### **C++**
73+
74+
```cpp
75+
76+
```
77+
78+
### **Go**
79+
80+
```go
81+
82+
```
83+
84+
### **...**
85+
86+
```
87+
88+
```
89+
90+
<!-- tabs:end -->
Loading
Loading

0 commit comments

Comments
 (0)