Skip to content

Commit 1b7040d

Browse files
committed
Add solution and test-cases for problem 3021
1 parent df4288a commit 1b7040d

File tree

4 files changed

+36
-26
lines changed

4 files changed

+36
-26
lines changed
19.7 KB
Loading

leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/README.md

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,39 @@
11
# [3021.Alice and Bob Playing Flower Game][title]
22

3-
> [!WARNING|style:flat]
4-
> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm)
5-
63
## Description
4+
Alice and Bob are playing a turn-based game on a field, with two lanes of flowers between them. There are `x` flowers in the first lane between Alice and Bob, and `y` flowers in the second lane between them.
5+
6+
![1](./1.png)
7+
8+
The game proceeds as follows:
9+
10+
1. Alice takes the first turn.
11+
2. In each turn, a player must choose either one of the lane and pick one flower from that side.
12+
3. At the end of the turn, if there are no flowers left at all, the current player captures their opponent and wins the game.
13+
14+
Given two integers, `n` and `m`, the task is to compute the number of possible pairs `(x, y)` that satisfy the conditions:
15+
16+
- Alice must win the game according to the described rules.
17+
- The number of flowers `x` in the first lane must be in the range `[1,n]`.
18+
- The number of flowers `y` in the second lane must be in the range `[1,m]`.
19+
20+
Return the number of possible pairs `(x, y)` that satisfy the conditions mentioned in the statement.
721

822
**Example 1:**
923

1024
```
11-
Input: a = "11", b = "1"
12-
Output: "100"
25+
Input: n = 3, m = 2
26+
Output: 3
27+
Explanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).
1328
```
1429

15-
## 题意
16-
> ...
17-
18-
## 题解
30+
**Example 2:**
1931

20-
### 思路1
21-
> ...
22-
Alice and Bob Playing Flower Game
23-
```go
2432
```
25-
33+
Input: n = 1, m = 1
34+
Output: 0
35+
Explanation: No pairs satisfy the conditions described in the statement.
36+
```
2637

2738
## 结语
2839

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package Solution
22

3-
func Solution(x bool) bool {
4-
return x
3+
func Solution(n int, m int) int64 {
4+
return int64(m) * int64(n) / 2
55
}

leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution_test.go

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,29 @@ func TestSolution(t *testing.T) {
1010
// 测试用例
1111
cases := []struct {
1212
name string
13-
inputs bool
14-
expect bool
13+
n, m int
14+
expect int64
1515
}{
16-
{"TestCase", true, true},
17-
{"TestCase", true, true},
18-
{"TestCase", false, false},
16+
{"TestCase1", 3, 2, 3},
17+
{"TestCase1", 1, 1, 0},
1918
}
2019

2120
// 开始测试
2221
for i, c := range cases {
2322
t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) {
24-
got := Solution(c.inputs)
23+
got := Solution(c.n, c.m)
2524
if !reflect.DeepEqual(got, c.expect) {
26-
t.Fatalf("expected: %v, but got: %v, with inputs: %v",
27-
c.expect, got, c.inputs)
25+
t.Fatalf("expected: %v, but got: %v, with inputs: %v %v",
26+
c.expect, got, c.n, c.m)
2827
}
2928
})
3029
}
3130
}
3231

33-
// 压力测试
32+
// 压力测试
3433
func BenchmarkSolution(b *testing.B) {
3534
}
3635

37-
// 使用案列
36+
// 使用案列
3837
func ExampleSolution() {
3938
}

0 commit comments

Comments
 (0)