diff --git a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/1.png b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/1.png new file mode 100644 index 000000000..31bdda50b Binary files /dev/null and b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/1.png differ diff --git a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/README.md b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/README.md index 5b4517997..8a1b3455b 100755 --- a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/README.md +++ b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/README.md @@ -1,28 +1,39 @@ # [3021.Alice and Bob Playing Flower Game][title] -> [!WARNING|style:flat] -> This question is temporarily unanswered if you have good ideas. Welcome to [Create Pull Request PR](https://github.com/kylesliu/awesome-golang-algorithm) - ## Description +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. + +![1](./1.png) + +The game proceeds as follows: + +1. Alice takes the first turn. +2. In each turn, a player must choose either one of the lane and pick one flower from that side. +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. + +Given two integers, `n` and `m`, the task is to compute the number of possible pairs `(x, y)` that satisfy the conditions: + +- Alice must win the game according to the described rules. +- The number of flowers `x` in the first lane must be in the range `[1,n]`. +- The number of flowers `y` in the second lane must be in the range `[1,m]`. + +Return the number of possible pairs `(x, y)` that satisfy the conditions mentioned in the statement. **Example 1:** ``` -Input: a = "11", b = "1" -Output: "100" +Input: n = 3, m = 2 +Output: 3 +Explanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1). ``` -## 题意 -> ... - -## 题解 +**Example 2:** -### 思路1 -> ... -Alice and Bob Playing Flower Game -```go ``` - +Input: n = 1, m = 1 +Output: 0 +Explanation: No pairs satisfy the conditions described in the statement. +``` ## 结语 diff --git a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution.go b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution.go index d115ccf5e..8bd7a5e5e 100644 --- a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution.go +++ b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution.go @@ -1,5 +1,5 @@ package Solution -func Solution(x bool) bool { - return x +func Solution(n int, m int) int64 { + return int64(m) * int64(n) / 2 } diff --git a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution_test.go b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution_test.go index 14ff50eb4..326d3ef6b 100644 --- a/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution_test.go +++ b/leetcode/3001-3100/3021.Alice-and-Bob-Playing-Flower-Game/Solution_test.go @@ -10,30 +10,29 @@ func TestSolution(t *testing.T) { // 测试用例 cases := []struct { name string - inputs bool - expect bool + n, m int + expect int64 }{ - {"TestCase", true, true}, - {"TestCase", true, true}, - {"TestCase", false, false}, + {"TestCase1", 3, 2, 3}, + {"TestCase1", 1, 1, 0}, } // 开始测试 for i, c := range cases { t.Run(c.name+" "+strconv.Itoa(i), func(t *testing.T) { - got := Solution(c.inputs) + got := Solution(c.n, c.m) if !reflect.DeepEqual(got, c.expect) { - t.Fatalf("expected: %v, but got: %v, with inputs: %v", - c.expect, got, c.inputs) + t.Fatalf("expected: %v, but got: %v, with inputs: %v %v", + c.expect, got, c.n, c.m) } }) } } -// 压力测试 +// 压力测试 func BenchmarkSolution(b *testing.B) { } -// 使用案列 +// 使用案列 func ExampleSolution() { }