3021. Alice and Bob Playing Flower Game Medium

@problem@discussion
#Math



1/**
2 * [3021] Alice and Bob Playing Flower Game
3 *
4 * Alice and Bob are playing a turn-based game on a circular field surrounded by flowers. The circle represents the field, and there are x flowers in the clockwise direction between Alice and Bob, and y flowers in the anti-clockwise direction between them.
5 * The game proceeds as follows:
6 * <ol>
7 * 	Alice takes the first turn.
8 * 	In each turn, a player must choose either the clockwise or anti-clockwise direction and pick one flower from that side.
9 * 	At the end of the turn, if there are no flowers left at all, the current player captures their opponent and wins the game.
10 * </ol>
11 * Given two integers, n and m, the task is to compute the number of possible pairs (x, y) that satisfy the conditions:
12 * 
13 * 	Alice must win the game according to the described rules.
14 * 	The number of flowers x in the clockwise direction must be in the range [1,n].
15 * 	The number of flowers y in the anti-clockwise direction must be in the range [1,m].
16 * 
17 * Return the number of possible pairs (x, y) that satisfy the conditions mentioned in the statement.
18 *  
19 * <strong class="example">Example 1:
20 * 
21 * Input: n = 3, m = 2
22 * Output: 3
23 * Explanation: The following pairs satisfy conditions described in the statement: (1,2), (3,2), (2,1).
24 * 
25 * <strong class="example">Example 2:
26 * 
27 * Input: n = 1, m = 1
28 * Output: 0
29 * Explanation: No pairs satisfy the conditions described in the statement.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	1 <= n, m <= 10^5
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/alice-and-bob-playing-flower-game/
40// discuss: https://leetcode.com/problems/alice-and-bob-playing-flower-game/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn flower_game(n: i32, m: i32) -> i64 {
46        
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_3021() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.