Skip to content

Commit 3d68c8a

Browse files
yanglbmeidoocs
andauthored
feat: add biweekly contest 123 (#2309)
Co-authored-by: Doocs Bot <doocs-bot@outlook.com>
1 parent c33bcc7 commit 3d68c8a

24 files changed

+686
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
# [3024. 三角形类型 II](https://leetcode.cn/problems/type-of-triangle-ii)
2+
3+
[English Version](/solution/3000-3099/3024.Type%20of%20Triangle%20II/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <code>3</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;,需要用它们来构造三角形。</p>
10+
11+
<ul>
12+
<li>如果一个三角形的所有边长度相等,那么这个三角形称为&nbsp;<strong>equilateral</strong>&nbsp;。</li>
13+
<li>如果一个三角形恰好有两条边长度相等,那么这个三角形称为&nbsp;<strong>isosceles</strong>&nbsp;。</li>
14+
<li>如果一个三角形三条边的长度互不相同,那么这个三角形称为&nbsp;<strong>scalene</strong>&nbsp;。</li>
15+
</ul>
16+
17+
<p>如果这个数组无法构成一个三角形,请你返回字符串&nbsp;<code>"none"</code>&nbsp;,否则返回一个字符串表示这个三角形的类型。</p>
18+
19+
<p>&nbsp;</p>
20+
21+
<p><strong class="example">示例 1:</strong></p>
22+
23+
<pre>
24+
<b>输入:</b>nums = [3,3,3]
25+
<b>输出:</b>"equilateral"
26+
<b>解释:</b>由于三条边长度相等,所以可以构成一个等边三角形,返回 "equilateral" 。
27+
</pre>
28+
29+
<p><strong class="example">示例 2:</strong></p>
30+
31+
<pre>
32+
<b>输入:</b>nums = [3,4,5]
33+
<b>输出:</b>"scalene"
34+
<b>解释:</b>
35+
nums[0] + nums[1] = 3 + 4 = 7 ,大于 nums[2] = 5<code>&nbsp;。</code>
36+
nums[0] + nums[2] = 3 + 5 = 8 ,大于 nums[1] = 4 。
37+
nums[1] + nums[2] = 4 + 5 = 9 ,大于 nums[0] = 3 。
38+
由于任意两边纸盒都大于第三边,所以可以构成一个三角形。
39+
因为三条边的长度互不相等,所以返回 "scalene" 。
40+
</pre>
41+
42+
<p>&nbsp;</p>
43+
44+
<p><strong>提示:</strong></p>
45+
46+
<ul>
47+
<li><code>nums.length == 3</code></li>
48+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
49+
</ul>
50+
51+
## 解法
52+
53+
### 方法一
54+
55+
<!-- tabs:start -->
56+
57+
```python
58+
59+
```
60+
61+
```java
62+
63+
```
64+
65+
```cpp
66+
67+
```
68+
69+
```go
70+
71+
```
72+
73+
<!-- tabs:end -->
74+
75+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
# [3024. Type of Triangle II](https://leetcode.com/problems/type-of-triangle-ii)
2+
3+
[中文文档](/solution/3000-3099/3024.Type%20of%20Triangle%20II/README.md)
4+
5+
## Description
6+
7+
<p>You are given a <strong>0-indexed</strong> integer array <code>nums</code> of size <code>3</code> which can form the sides of a triangle.</p>
8+
9+
<ul>
10+
<li>A triangle is called <strong>equilateral</strong> if it has all sides of equal length.</li>
11+
<li>A triangle is called <strong>isosceles</strong> if it has exactly two sides of equal length.</li>
12+
<li>A triangle is called <strong>scalene</strong> if all its sides are of different lengths.</li>
13+
</ul>
14+
15+
<p>Return <em>a string representing</em> <em>the type of triangle that can be formed </em><em>or </em><code>&quot;none&quot;</code><em> if it <strong>cannot</strong> form a triangle.</em></p>
16+
17+
<p>&nbsp;</p>
18+
<p><strong class="example">Example 1:</strong></p>
19+
20+
<pre>
21+
<strong>Input:</strong> nums = [3,3,3]
22+
<strong>Output:</strong> &quot;equilateral&quot;
23+
<strong>Explanation:</strong> Since all the sides are of equal length, therefore, it will form an equilateral triangle.
24+
</pre>
25+
26+
<p><strong class="example">Example 2:</strong></p>
27+
28+
<pre>
29+
<strong>Input:</strong> nums = [3,4,5]
30+
<strong>Output:</strong> &quot;scalene&quot;
31+
<strong>Explanation:</strong>
32+
nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
33+
nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
34+
nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
35+
Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
36+
As all the sides are of different lengths, it will form a scalene triangle.
37+
</pre>
38+
39+
<p>&nbsp;</p>
40+
<p><strong>Constraints:</strong></p>
41+
42+
<ul>
43+
<li><code>nums.length == 3</code></li>
44+
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
45+
</ul>
46+
47+
## Solutions
48+
49+
### Solution 1
50+
51+
<!-- tabs:start -->
52+
53+
```python
54+
55+
```
56+
57+
```java
58+
59+
```
60+
61+
```cpp
62+
63+
```
64+
65+
```go
66+
67+
```
68+
69+
<!-- tabs:end -->
70+
71+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
# [3025. 人员站位的方案数 I](https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-i)
2+
3+
[English Version](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README_EN.md)
4+
5+
## 题目描述
6+
7+
<!-- 这里写题目描述 -->
8+
9+
<p>给你一个&nbsp;&nbsp;<code>n x 2</code>&nbsp;的二维数组 <code>points</code>&nbsp;,它表示二维平面上的一些点坐标,其中&nbsp;<code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>&nbsp;。</p>
10+
11+
<p>我们定义 x 轴的正方向为 <strong>右</strong>&nbsp;(<strong>x 轴递增的方向</strong>),x 轴的负方向为 <strong>左</strong>&nbsp;(<strong>x 轴递减的方向</strong>)。类似的,我们定义 y 轴的正方向为 <strong>上</strong>&nbsp;(<strong>y 轴递增的方向</strong>),y 轴的负方向为 <strong>下</strong>&nbsp;(<strong>y 轴递减的方向</strong>)。</p>
12+
13+
<p>你需要安排这 <code>n</code>&nbsp;个人的站位,这 <code>n</code>&nbsp;个人中包括&nbsp;liupengsay 和小羊肖恩&nbsp;。你需要确保每个点处&nbsp;<strong>恰好</strong>&nbsp;&nbsp;<strong>一个</strong>&nbsp;人。同时,liupengsay 想跟小羊肖恩单独玩耍,所以&nbsp;liupengsay&nbsp;会以 liupengsay<b>&nbsp;</b>的坐标为 <strong>左上角</strong>&nbsp;,小羊肖恩的坐标为 <strong>右下角</strong>&nbsp;建立一个矩形的围栏(<strong>注意</strong>,围栏可能&nbsp;<strong>不</strong> 包含任何区域,也就是说围栏可能是一条线段)。如果围栏的 <strong>内部</strong>&nbsp;或者 <strong>边缘</strong>&nbsp;上有任何其他人,liupengsay 都会难过。</p>
14+
15+
<p>请你在确保 liupengsay&nbsp;<strong>不会</strong> 难过的前提下,返回 liupengsay 和小羊肖恩可以选择的 <strong>点对</strong>&nbsp;数目。</p>
16+
17+
<p><b>注意</b>,liupengsay 建立的围栏必须确保 liupengsay 的位置是矩形的左上角,小羊肖恩的位置是矩形的右下角。比方说,以&nbsp;<code>(1, 1)</code>&nbsp;,<code>(1, 3)</code>&nbsp;,<code>(3, 1)</code>&nbsp;&nbsp;<code>(3, 3)</code>&nbsp;为矩形的四个角,给定下图的两个输入,liupengsay 都不能建立围栏,原因如下:</p>
18+
19+
<ul>
20+
<li>图一中,liupengsay 在&nbsp;<code>(3, 3)</code>&nbsp;且小羊肖恩在&nbsp;<code>(1, 1)</code>&nbsp;,liupengsay 的位置不是左上角且小羊肖恩的位置不是右下角。</li>
21+
<li>图二中,liupengsay 在&nbsp;<code>(1, 3)</code>&nbsp;且小羊肖恩在&nbsp;<code>(1, 1)</code>&nbsp;,小羊肖恩的位置不是在围栏的右下角。</li>
22+
</ul>
23+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example0alicebob-1.png" style="width: 750px; height: 308px;padding: 10px; background: #fff; border-radius: .5rem;" />
24+
<p>&nbsp;</p>
25+
26+
<p><strong class="example">示例 1:</strong></p>
27+
28+
<p><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example1alicebob.png" style="width: 376px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" /></p>
29+
30+
<pre>
31+
<b>输入:</b>points = [[1,1],[2,2],[3,3]]
32+
<b>输出:</b>0
33+
<strong>解释:</strong>没有办法可以让 liupengsay 的围栏以 liupengsay 的位置为左上角且小羊肖恩的位置为右下角。所以我们返回 0 。
34+
</pre>
35+
36+
<p><strong class="example">示例 2:</strong></p>
37+
38+
<p><strong class="example"><a href="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/1706880313-YelabI-example2.jpeg"><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/1706880313-YelabI-example2.jpeg" style="width: 900px; height: 247px;" /></a></strong></p>
39+
40+
<pre>
41+
<b>输入:</b>points = [[6,2],[4,4],[2,6]]
42+
<b>输出:</b>2
43+
<b>解释:</b>总共有 2 种方案安排 liupengsay 和小羊肖恩的位置,使得 liupengsay 不会难过:
44+
- liupengsay 站在 (4, 4) ,小羊肖恩站在 (6, 2) 。
45+
- liupengsay 站在 (2, 6) ,小羊肖恩站在 (4, 4) 。
46+
不能安排 liupengsay 站在 (2, 6) 且小羊肖恩站在 (6, 2) ,因为站在 (4, 4) 的人处于围栏内。
47+
</pre>
48+
49+
<p><strong class="example">示例 3:</strong></p>
50+
51+
<p><strong class="example"><a href="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/1706880311-mtPGYC-example3.jpeg"><img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/1706880311-mtPGYC-example3.jpeg" style="width: 900px; height: 247px;" /></a></strong></p>
52+
53+
<pre>
54+
<b>输入:</b>points = [[3,1],[1,3],[1,1]]
55+
<b>输出:</b>2
56+
<b>解释:</b>总共有 2 种方案安排 liupengsay 和小羊肖恩的位置,使得 liupengsay 不会难过:
57+
- liupengsay 站在 (1, 1) ,小羊肖恩站在 (3, 1) 。
58+
- liupengsay 站在 (1, 3) ,小羊肖恩站在 (1, 1) 。
59+
不能安排 liupengsay 站在 (1, 3) 且小羊肖恩站在 (3, 1) ,因为站在 (1, 1) 的人处于围栏内。
60+
注意围栏是可以不包含任何面积的,上图中第一和第二个围栏都是合法的。
61+
</pre>
62+
63+
<p>&nbsp;</p>
64+
65+
<p><strong>提示:</strong></p>
66+
67+
<ul>
68+
<li><code>2 &lt;= n &lt;= 50</code></li>
69+
<li><code>points[i].length == 2</code></li>
70+
<li><code>0 &lt;= points[i][0], points[i][1] &lt;= 50</code></li>
71+
<li><code>points[i]</code>&nbsp;点对两两不同。</li>
72+
</ul>
73+
74+
## 解法
75+
76+
### 方法一
77+
78+
<!-- tabs:start -->
79+
80+
```python
81+
82+
```
83+
84+
```java
85+
86+
```
87+
88+
```cpp
89+
90+
```
91+
92+
```go
93+
94+
```
95+
96+
<!-- tabs:end -->
97+
98+
<!-- end -->
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# [3025. Find the Number of Ways to Place People I](https://leetcode.com/problems/find-the-number-of-ways-to-place-people-i)
2+
3+
[中文文档](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README.md)
4+
5+
## Description
6+
7+
<p>You are given a 2D array <code>points</code> of size <code>n x 2</code> representing integer coordinates of some points on a 2D-plane, where <code>points[i] = [x<sub>i</sub>, y<sub>i</sub>]</code>.</p>
8+
9+
<p>We define the <strong>right</strong> direction as positive x-axis (<strong>increasing x-coordinate</strong>) and the <strong>left</strong> direction as negative x-axis (<strong>decreasing x-coordinate</strong>). Similarly, we define the <strong>up</strong> direction as positive y-axis (<strong>increasing y-coordinate</strong>) and the <strong>down</strong> direction as negative y-axis (<strong>decreasing y-coordinate</strong>)</p>
10+
11+
<p>You have to place <code>n</code> people, including Chisato and Takina, at these points such that there is <strong>exactly one</strong> person at every point. Chisato wants to be alone with Takina, so Chisato will build a rectangular fence with Chisato&#39;s position as the <strong>upper left corner</strong> and Takina&#39;s position as the <strong>lower right corner</strong> of the fence (<strong>Note</strong> that the fence <strong>might not</strong> enclose any area, i.e. it can be a line). If any person other than Chisato and Takina is either <strong>inside</strong> the fence or <strong>on</strong> the fence, Chisato will be sad.</p>
12+
13+
<p>Return <em>the number of <strong>pairs of points</strong> where you can place Chisato and Takina, such that Chisato <strong>does not</strong> become sad on building the fence</em>.</p>
14+
15+
<p><strong>Note</strong> that Chisato can only build a fence with Chisato&#39;s position as the upper left corner, and Takina&#39;s position as the lower right corner. For example, Chisato cannot build either of the fences in the picture below with four corners <code>(1, 1)</code>, <code>(1, 3)</code>, <code>(3, 1)</code>, and <code>(3, 3)</code>, because:</p>
16+
17+
<ul>
18+
<li>With Chisato at <code>(3, 3)</code> and Takina at <code>(1, 1)</code>, Chisato&#39;s position is not the upper left corner and Takina&#39;s position is not the lower right corner of the fence.</li>
19+
<li>With Chisato at <code>(1, 3)</code> and Takina at <code>(1, 1)</code>, Takina&#39;s position is not the lower right corner of the fence.</li>
20+
</ul>
21+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example0alicebob-1.png" style="width: 750px; height: 308px;padding: 10px; background: #fff; border-radius: .5rem;" />
22+
<p>&nbsp;</p>
23+
<p><strong class="example">Example 1:</strong></p>
24+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example1alicebob.png" style="width: 376px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
25+
<pre>
26+
<strong>Input:</strong> points = [[1,1],[2,2],[3,3]]
27+
<strong>Output:</strong> 0
28+
<strong>Explanation:</strong> There is no way to place Chisato and Takina such that Chisato can build a fence with Chisato&#39;s position as the upper left corner and Takina&#39;s position as the lower right corner. Hence we return 0.
29+
</pre>
30+
31+
<p><strong class="example">Example 2:</strong></p>
32+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/example2chisatotakina.png" style="width: 1121px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
33+
<pre>
34+
<strong>Input:</strong> points = [[6,2],[4,4],[2,6]]
35+
<strong>Output:</strong> 2
36+
<strong>Explanation:</strong> There are two ways to place Chisato and Takina such that Chisato will not be sad:
37+
- Place Chisato at (4, 4) and Takina at (6, 2).
38+
- Place Chisato at (2, 6) and Takina at (4, 4).
39+
You cannot place Chisato at (2, 6) and Takina at (6, 2) because the person at (4, 4) will be inside the fence.
40+
</pre>
41+
42+
<p><strong class="example">Example 3:</strong></p>
43+
<img alt="" src="https://fastly.jsdelivr.net/gh/doocs/leetcode@main/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/images/chisatotakinaexample3.png" style="width: 1123px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
44+
<pre>
45+
<strong>Input:</strong> points = [[3,1],[1,3],[1,1]]
46+
<strong>Output:</strong> 2
47+
<strong>Explanation:</strong> There are two ways to place Chisato and Takina such that Chisato will not be sad:
48+
- Place Chisato at (1, 1) and Takina at (3, 1).
49+
- Place Chisato at (1, 3) and Takina at (1, 1).
50+
You cannot place Chisato at (1, 3) and Takina at (3, 1) because the person at (1, 1) will be on the fence.
51+
Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.
52+
</pre>
53+
54+
<p>&nbsp;</p>
55+
<p><strong>Constraints:</strong></p>
56+
57+
<ul>
58+
<li><code>2 &lt;= n &lt;= 50</code></li>
59+
<li><code>points[i].length == 2</code></li>
60+
<li><code>0 &lt;= points[i][0], points[i][1] &lt;= 50</code></li>
61+
<li>All <code>points[i]</code> are distinct.</li>
62+
</ul>
63+
64+
## Solutions
65+
66+
### Solution 1
67+
68+
<!-- tabs:start -->
69+
70+
```python
71+
72+
```
73+
74+
```java
75+
76+
```
77+
78+
```cpp
79+
80+
```
81+
82+
```go
83+
84+
```
85+
86+
<!-- tabs:end -->
87+
88+
<!-- end -->
Loading

0 commit comments

Comments
 (0)