2550. Count Collisions of Monkeys on a Polygon Medium

@problem@discussion
#Math#Recursion



1/**
2 * [2550] Count Collisions of Monkeys on a Polygon
3 *
4 * There is a regular convex polygon with n vertices. The vertices are labeled from 0 to n - 1 in a clockwise direction, and each vertex has exactly one monkey. The following figure shows a convex polygon of 6 vertices.
5 * <img alt="" src="https://assets.leetcode.com/uploads/2023/01/22/hexagon.jpg" style="width: 300px; height: 293px;" />
6 * Each monkey moves simultaneously to a neighboring vertex. A neighboring vertex for a vertex i can be:
7 * 
8 * 	the vertex (i + 1) % n in the clockwise direction, or
9 * 	the vertex (i - 1 + n) % n in the counter-clockwise direction.
10 * 
11 * A collision happens if at least two monkeys reside on the same vertex after the movement or intersect on an edge.
12 * Return the number of ways the monkeys can move so that at least one collision  happens. Since the answer may be very large, return it modulo 10^9 + 7.
13 * Note that each monkey can only move once.
14 *  
15 * <strong class="example">Example 1:
16 * 
17 * Input: n = 3
18 * Output: 6
19 * Explanation: There are 8 total possible movements.
20 * Two ways such that they collide at some point are:
21 * - Monkey 1 moves in a clockwise direction; monkey 2 moves in an anticlockwise direction; monkey 3 moves in a clockwise direction. Monkeys 1 and 2 collide.
22 * - Monkey 1 moves in an anticlockwise direction; monkey 2 moves in an anticlockwise direction; monkey 3 moves in a clockwise direction. Monkeys 1 and 3 collide.
23 * It can be shown 6 total movements result in a collision.
24 * 
25 * <strong class="example">Example 2:
26 * 
27 * Input: n = 4
28 * Output: 14
29 * Explanation: It can be shown that there are 14 ways for the monkeys to collide.
30 * 
31 *  
32 * Constraints:
33 * 
34 * 	3 <= n <= 10^9
35 * 
36 */
37pub struct Solution {}
38
39// problem: https://leetcode.com/problems/count-collisions-of-monkeys-on-a-polygon/
40// discuss: https://leetcode.com/problems/count-collisions-of-monkeys-on-a-polygon/discuss/?currentPage=1&orderBy=most_votes&query=
41
42// submission codes start here
43
44impl Solution {
45    pub fn monkey_move(n: i32) -> i32 {
46        0
47    }
48}
49
50// submission codes end
51
52#[cfg(test)]
53mod tests {
54    use super::*;
55
56    #[test]
57    fn test_2550() {
58    }
59}
60


Back
© 2025 bowen.ge All Rights Reserved.