Skip to content

Commit 0c82425

Browse files
committed
+ problem 2481
1 parent 53e7629 commit 0c82425

File tree

5 files changed

+113
-0
lines changed

5 files changed

+113
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# 2481. Minimum Cuts to Divide a Circle
2+
A **valid cut** in a circle can be:
3+
4+
* A cut that is represented by a straight line that touches two points on the edge of the circle and passes through its center, or
5+
* A cut that is represented by a straight line that touches one point on the edge of the circle and its center.
6+
7+
Some valid and invalid cuts are shown in the figures below.
8+
9+
![](https://assets.leetcode.com/uploads/2022/10/29/alldrawio.png)
10+
11+
Given the integer `n`, return *the **minimum** number of cuts needed to divide a circle into* `n` *equal slices*.
12+
13+
#### Example 1:
14+
![](https://assets.leetcode.com/uploads/2022/10/24/11drawio.png)
15+
<pre>
16+
<strong>Input:</strong> n = 4
17+
<strong>Output:</strong> 2
18+
<strong>Explanation:</strong>
19+
The above figure shows how cutting the circle twice through the middle divides it into 4 equal slices.
20+
</pre>
21+
22+
#### Example 2:
23+
![](https://assets.leetcode.com/uploads/2022/10/24/22drawio.png)
24+
<pre>
25+
<strong>Input:</strong> n = 3
26+
<strong>Output:</strong> 3
27+
<strong>Explanation:</strong>
28+
At least 3 cuts are needed to divide the circle into 3 equal slices.
29+
It can be shown that less than 3 cuts cannot result in 3 slices of equal size and shape.
30+
Also note that the first cut will not divide the circle into distinct parts.
31+
</pre>
32+
33+
#### Constraints:
34+
* `1 <= n <= 100`
35+
36+
## Solutions (Rust)
37+
38+
### 1. Solution
39+
```Rust
40+
impl Solution {
41+
pub fn number_of_cuts(n: i32) -> i32 {
42+
if n == 1 || n % 2 == 0 {
43+
n / 2
44+
} else {
45+
n
46+
}
47+
}
48+
}
49+
```
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
# 2481. 分割圆的最少切割次数
2+
圆内一个 **有效切割** ,符合以下二者之一:
3+
4+
* 该切割是两个端点在圆上的线段,且该线段经过圆心。
5+
* 该切割是一端在圆心另一端在圆上的线段。
6+
7+
一些有效和无效的切割如下图所示。
8+
9+
![](https://assets.leetcode.com/uploads/2022/10/29/alldrawio.png)
10+
11+
给你一个整数 `n` ,请你返回将圆切割成相等的 `n` 等分的 **最少** 切割次数。
12+
13+
#### 示例 1:
14+
![](https://assets.leetcode.com/uploads/2022/10/24/11drawio.png)
15+
<pre>
16+
<strong>输入:</strong> n = 4
17+
<strong>输出:</strong> 2
18+
<strong>解释:</strong>
19+
上图展示了切割圆 2 次,得到四等分。
20+
</pre>
21+
22+
#### 示例 2:
23+
![](https://assets.leetcode.com/uploads/2022/10/24/22drawio.png)
24+
<pre>
25+
<strong>输入:</strong> n = 3
26+
<strong>输出:</strong> 3
27+
<strong>解释:</strong>
28+
最少需要切割 3 次,将圆切成三等分。
29+
少于 3 次切割无法将圆切成大小相等面积相同的 3 等分。
30+
同时可以观察到,第一次切割无法将圆切割开。
31+
</pre>
32+
33+
#### 提示:
34+
* `1 <= n <= 100`
35+
36+
## 题解 (Rust)
37+
38+
### 1. 题解
39+
```Rust
40+
impl Solution {
41+
pub fn number_of_cuts(n: i32) -> i32 {
42+
if n == 1 || n % 2 == 0 {
43+
n / 2
44+
} else {
45+
n
46+
}
47+
}
48+
}
49+
```
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
impl Solution {
2+
pub fn number_of_cuts(n: i32) -> i32 {
3+
if n == 1 || n % 2 == 0 {
4+
n / 2
5+
} else {
6+
n
7+
}
8+
}
9+
}

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@
11251125
[2465][2465l]|[Number of Distinct Averages][2465] |![rs]
11261126
[2469][2469l]|[Convert the Temperature][2469] |![rs]
11271127
[2475][2475l]|[Number of Unequal Triplets in Array][2475] |![rs]
1128+
[2481][2481l]|[Minimum Cuts to Divide a Circle][2481] |![rs]
11281129
[2482][2482l]|[Difference Between Ones and Zeros in Row and Column][2482] |![rs]
11291130
[2483][2483l]|[Minimum Penalty for a Shop][2483] |![rs]
11301131
[2490][2490l]|[Circular Sentence][2490] |![py]
@@ -2278,6 +2279,7 @@
22782279
[2465]:Problemset/2465-Number%20of%20Distinct%20Averages/README.md#2465-number-of-distinct-averages
22792280
[2469]:Problemset/2469-Convert%20the%20Temperature/README.md#2469-convert-the-temperature
22802281
[2475]:Problemset/2475-Number%20of%20Unequal%20Triplets%20in%20Array/README.md#2475-number-of-unequal-triplets-in-array
2282+
[2481]:Problemset/2481-Minimum%20Cuts%20to%20Divide%20a%20Circle/README.md#2481-minimum-cuts-to-divide-a-circle
22812283
[2482]:Problemset/2482-Difference%20Between%20Ones%20and%20Zeros%20in%20Row%20and%20Column/README.md#2482-difference-between-ones-and-zeros-in-row-and-column
22822284
[2483]:Problemset/2483-Minimum%20Penalty%20for%20a%20Shop/README.md#2483-minimum-penalty-for-a-shop
22832285
[2490]:Problemset/2490-Circular%20Sentence/README.md#2490-circular-sentence
@@ -3436,6 +3438,7 @@
34363438
[2465l]:https://leetcode.com/problems/number-of-distinct-averages/
34373439
[2469l]:https://leetcode.com/problems/convert-the-temperature/
34383440
[2475l]:https://leetcode.com/problems/number-of-unequal-triplets-in-array/
3441+
[2481l]:https://leetcode.com/problems/minimum-cuts-to-divide-a-circle/
34393442
[2482l]:https://leetcode.com/problems/difference-between-ones-and-zeros-in-row-and-column/
34403443
[2483l]:https://leetcode.com/problems/minimum-penalty-for-a-shop/
34413444
[2490l]:https://leetcode.com/problems/circular-sentence/

README_CN.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1125,6 +1125,7 @@
11251125
[2465][2465l]|[不同的平均值数目][2465] |![rs]
11261126
[2469][2469l]|[温度转换][2469] |![rs]
11271127
[2475][2475l]|[数组中不等三元组的数目][2475] |![rs]
1128+
[2481][2481l]|[分割圆的最少切割次数][2481] |![rs]
11281129
[2482][2482l]|[行和列中一和零的差值][2482] |![rs]
11291130
[2483][2483l]|[商店的最少代价][2483] |![rs]
11301131
[2490][2490l]|[回环句][2490] |![py]
@@ -2278,6 +2279,7 @@
22782279
[2465]:Problemset/2465-Number%20of%20Distinct%20Averages/README_CN.md#2465-不同的平均值数目
22792280
[2469]:Problemset/2469-Convert%20the%20Temperature/README_CN.md#2469-温度转换
22802281
[2475]:Problemset/2475-Number%20of%20Unequal%20Triplets%20in%20Array/README_CN.md#2475-数组中不等三元组的数目
2282+
[2481]:Problemset/2481-Minimum%20Cuts%20to%20Divide%20a%20Circle/README_CN.md#2481-分割圆的最少切割次数
22812283
[2482]:Problemset/2482-Difference%20Between%20Ones%20and%20Zeros%20in%20Row%20and%20Column/README_CN.md#2482-行和列中一和零的差值
22822284
[2483]:Problemset/2483-Minimum%20Penalty%20for%20a%20Shop/README_CN.md#2483-商店的最少代价
22832285
[2490]:Problemset/2490-Circular%20Sentence/README_CN.md#2490-回环句
@@ -3436,6 +3438,7 @@
34363438
[2465l]:https://leetcode.cn/problems/number-of-distinct-averages/
34373439
[2469l]:https://leetcode.cn/problems/convert-the-temperature/
34383440
[2475l]:https://leetcode.cn/problems/number-of-unequal-triplets-in-array/
3441+
[2481l]:https://leetcode.cn/problems/minimum-cuts-to-divide-a-circle/
34393442
[2482l]:https://leetcode.cn/problems/difference-between-ones-and-zeros-in-row-and-column/
34403443
[2483l]:https://leetcode.cn/problems/minimum-penalty-for-a-shop/
34413444
[2490l]:https://leetcode.cn/problems/circular-sentence/

0 commit comments

Comments
 (0)