Skip to content
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

feat: add biweekly contest 123 #2309

Merged
merged 2 commits into from
Feb 4, 2024
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
75 changes: 75 additions & 0 deletions solution/3000-3099/3024.Type of Triangle II/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
# [3024. 三角形类型 II](https://leetcode.cn/problems/type-of-triangle-ii)

[English Version](/solution/3000-3099/3024.Type%20of%20Triangle%20II/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

<p>给你一个下标从 <strong>0</strong>&nbsp;开始长度为 <code>3</code>&nbsp;的整数数组&nbsp;<code>nums</code>&nbsp;,需要用它们来构造三角形。</p>

<ul>
<li>如果一个三角形的所有边长度相等,那么这个三角形称为&nbsp;<strong>equilateral</strong>&nbsp;。</li>
<li>如果一个三角形恰好有两条边长度相等,那么这个三角形称为&nbsp;<strong>isosceles</strong>&nbsp;。</li>
<li>如果一个三角形三条边的长度互不相同,那么这个三角形称为&nbsp;<strong>scalene</strong>&nbsp;。</li>
</ul>

<p>如果这个数组无法构成一个三角形,请你返回字符串&nbsp;<code>"none"</code>&nbsp;,否则返回一个字符串表示这个三角形的类型。</p>

<p>&nbsp;</p>

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

<pre>
<b>输入:</b>nums = [3,3,3]
<b>输出:</b>"equilateral"
<b>解释:</b>由于三条边长度相等,所以可以构成一个等边三角形,返回 "equilateral" 。
</pre>

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

<pre>
<b>输入:</b>nums = [3,4,5]
<b>输出:</b>"scalene"
<b>解释:</b>
nums[0] + nums[1] = 3 + 4 = 7 ,大于 nums[2] = 5<code>&nbsp;。</code>
nums[0] + nums[2] = 3 + 5 = 8 ,大于 nums[1] = 4 。
nums[1] + nums[2] = 4 + 5 = 9 ,大于 nums[0] = 3 。
由于任意两边纸盒都大于第三边,所以可以构成一个三角形。
因为三条边的长度互不相等,所以返回 "scalene" 。
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>nums.length == 3</code></li>
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
</ul>

## 解法

### 方法一

<!-- tabs:start -->

```python

```

```java

```

```cpp

```

```go

```

<!-- tabs:end -->

<!-- end -->
71 changes: 71 additions & 0 deletions solution/3000-3099/3024.Type of Triangle II/README_EN.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# [3024. Type of Triangle II](https://leetcode.com/problems/type-of-triangle-ii)

[中文文档](/solution/3000-3099/3024.Type%20of%20Triangle%20II/README.md)

## Description

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

<ul>
<li>A triangle is called <strong>equilateral</strong> if it has all sides of equal length.</li>
<li>A triangle is called <strong>isosceles</strong> if it has exactly two sides of equal length.</li>
<li>A triangle is called <strong>scalene</strong> if all its sides are of different lengths.</li>
</ul>

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

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

<pre>
<strong>Input:</strong> nums = [3,3,3]
<strong>Output:</strong> &quot;equilateral&quot;
<strong>Explanation:</strong> Since all the sides are of equal length, therefore, it will form an equilateral triangle.
</pre>

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

<pre>
<strong>Input:</strong> nums = [3,4,5]
<strong>Output:</strong> &quot;scalene&quot;
<strong>Explanation:</strong>
nums[0] + nums[1] = 3 + 4 = 7, which is greater than nums[2] = 5.
nums[0] + nums[2] = 3 + 5 = 8, which is greater than nums[1] = 4.
nums[1] + nums[2] = 4 + 5 = 9, which is greater than nums[0] = 3.
Since the sum of the two sides is greater than the third side for all three cases, therefore, it can form a triangle.
As all the sides are of different lengths, it will form a scalene triangle.
</pre>

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

<ul>
<li><code>nums.length == 3</code></li>
<li><code>1 &lt;= nums[i] &lt;= 100</code></li>
</ul>

## Solutions

### Solution 1

<!-- tabs:start -->

```python

```

```java

```

```cpp

```

```go

```

<!-- tabs:end -->

<!-- end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
# [3025. 人员站位的方案数 I](https://leetcode.cn/problems/find-the-number-of-ways-to-place-people-i)

[English Version](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README_EN.md)

## 题目描述

<!-- 这里写题目描述 -->

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

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

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

<p>请你在确保 liupengsay&nbsp;<strong>不会</strong> 难过的前提下,返回 liupengsay 和小羊肖恩可以选择的 <strong>点对</strong>&nbsp;数目。</p>

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

<ul>
<li>图一中,liupengsay 在&nbsp;<code>(3, 3)</code>&nbsp;且小羊肖恩在&nbsp;<code>(1, 1)</code>&nbsp;,liupengsay 的位置不是左上角且小羊肖恩的位置不是右下角。</li>
<li>图二中,liupengsay 在&nbsp;<code>(1, 3)</code>&nbsp;且小羊肖恩在&nbsp;<code>(1, 1)</code>&nbsp;,小羊肖恩的位置不是在围栏的右下角。</li>
</ul>
<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;" />
<p>&nbsp;</p>

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

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

<pre>
<b>输入:</b>points = [[1,1],[2,2],[3,3]]
<b>输出:</b>0
<strong>解释:</strong>没有办法可以让 liupengsay 的围栏以 liupengsay 的位置为左上角且小羊肖恩的位置为右下角。所以我们返回 0 。
</pre>

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

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

<pre>
<b>输入:</b>points = [[6,2],[4,4],[2,6]]
<b>输出:</b>2
<b>解释:</b>总共有 2 种方案安排 liupengsay 和小羊肖恩的位置,使得 liupengsay 不会难过:
- liupengsay 站在 (4, 4) ,小羊肖恩站在 (6, 2) 。
- liupengsay 站在 (2, 6) ,小羊肖恩站在 (4, 4) 。
不能安排 liupengsay 站在 (2, 6) 且小羊肖恩站在 (6, 2) ,因为站在 (4, 4) 的人处于围栏内。
</pre>

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

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

<pre>
<b>输入:</b>points = [[3,1],[1,3],[1,1]]
<b>输出:</b>2
<b>解释:</b>总共有 2 种方案安排 liupengsay 和小羊肖恩的位置,使得 liupengsay 不会难过:
- liupengsay 站在 (1, 1) ,小羊肖恩站在 (3, 1) 。
- liupengsay 站在 (1, 3) ,小羊肖恩站在 (1, 1) 。
不能安排 liupengsay 站在 (1, 3) 且小羊肖恩站在 (3, 1) ,因为站在 (1, 1) 的人处于围栏内。
注意围栏是可以不包含任何面积的,上图中第一和第二个围栏都是合法的。
</pre>

<p>&nbsp;</p>

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

<ul>
<li><code>2 &lt;= n &lt;= 50</code></li>
<li><code>points[i].length == 2</code></li>
<li><code>0 &lt;= points[i][0], points[i][1] &lt;= 50</code></li>
<li><code>points[i]</code>&nbsp;点对两两不同。</li>
</ul>

## 解法

### 方法一

<!-- tabs:start -->

```python

```

```java

```

```cpp

```

```go

```

<!-- tabs:end -->

<!-- end -->
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# [3025. Find the Number of Ways to Place People I](https://leetcode.com/problems/find-the-number-of-ways-to-place-people-i)

[中文文档](/solution/3000-3099/3025.Find%20the%20Number%20of%20Ways%20to%20Place%20People%20I/README.md)

## Description

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

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

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

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

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

<ul>
<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>
<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>
</ul>
<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;" />
<p>&nbsp;</p>
<p><strong class="example">Example 1:</strong></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;" />
<pre>
<strong>Input:</strong> points = [[1,1],[2,2],[3,3]]
<strong>Output:</strong> 0
<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.
</pre>

<p><strong class="example">Example 2:</strong></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/example2chisatotakina.png" style="width: 1121px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
<pre>
<strong>Input:</strong> points = [[6,2],[4,4],[2,6]]
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are two ways to place Chisato and Takina such that Chisato will not be sad:
- Place Chisato at (4, 4) and Takina at (6, 2).
- Place Chisato at (2, 6) and Takina at (4, 4).
You cannot place Chisato at (2, 6) and Takina at (6, 2) because the person at (4, 4) will be inside the fence.
</pre>

<p><strong class="example">Example 3:</strong></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/chisatotakinaexample3.png" style="width: 1123px; height: 308px; padding: 10px; background: rgb(255, 255, 255); border-radius: 0.5rem;" />
<pre>
<strong>Input:</strong> points = [[3,1],[1,3],[1,1]]
<strong>Output:</strong> 2
<strong>Explanation:</strong> There are two ways to place Chisato and Takina such that Chisato will not be sad:
- Place Chisato at (1, 1) and Takina at (3, 1).
- Place Chisato at (1, 3) and Takina at (1, 1).
You cannot place Chisato at (1, 3) and Takina at (3, 1) because the person at (1, 1) will be on the fence.
Note that it does not matter if the fence encloses any area, the first and second fences in the image are valid.
</pre>

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

<ul>
<li><code>2 &lt;= n &lt;= 50</code></li>
<li><code>points[i].length == 2</code></li>
<li><code>0 &lt;= points[i][0], points[i][1] &lt;= 50</code></li>
<li>All <code>points[i]</code> are distinct.</li>
</ul>

## Solutions

### Solution 1

<!-- tabs:start -->

```python

```

```java

```

```cpp

```

```go

```

<!-- tabs:end -->

<!-- end -->
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading