799. Champagne Tower Medium
1/**
2 * [799] Champagne Tower
3 *
4 * We stack glasses in a pyramid, where the first row has 1 glass, the second row has 2 glasses, and so on until the 100^th row. Each glass holds one cup of champagne.
5 *
6 * Then, some champagne is poured into the first glass at the top. When the topmost glass is full, any excess liquid poured will fall equally to the glass immediately to the left and right of it. When those glasses become full, any excess champagne will fall equally to the left and right of those glasses, and so on. (A glass at the bottom row has its excess champagne fall on the floor.)
7 *
8 * For example, after one cup of champagne is poured, the top most glass is full. After two cups of champagne are poured, the two glasses on the second row are half full. After three cups of champagne are poured, those two cups become full - there are 3 full glasses total now. After four cups of champagne are poured, the third row has the middle glass half full, and the two outside glasses are a quarter full, as pictured below.
9 *
10 * <img alt="" src="https://s3-lc-upload.s3.amazonaws.com/uploads/2018/03/09/tower.png" style="height: 241px; width: 350px;" />
11 *
12 * Now after pouring some non-negative integer cups of champagne, return how full the j^th glass in the i^th row is (both i and j are 0-indexed.)
13 *
14 *
15 * Example 1:
16 *
17 *
18 * Input: poured = 1, query_row = 1, query_glass = 1
19 * Output: 0.00000
20 * Explanation: We poured 1 cup of champange to the top glass of the tower (which is indexed as (0, 0)). There will be no excess liquid so all the glasses under the top glass will remain empty.
21 *
22 *
23 * Example 2:
24 *
25 *
26 * Input: poured = 2, query_row = 1, query_glass = 1
27 * Output: 0.50000
28 * Explanation: We poured 2 cups of champange to the top glass of the tower (which is indexed as (0, 0)). There is one cup of excess liquid. The glass indexed as (1, 0) and the glass indexed as (1, 1) will share the excess liquid equally, and each will get half cup of champange.
29 *
30 *
31 * Example 3:
32 *
33 *
34 * Input: poured = 100000009, query_row = 33, query_glass = 17
35 * Output: 1.00000
36 *
37 *
38 *
39 * Constraints:
40 *
41 *
42 * 0 <= poured <= 10^9
43 * 0 <= query_glass <= query_row < 100
44 *
45 */
46pub struct Solution {}
47
48// problem: https://leetcode.com/problems/champagne-tower/
49// discuss: https://leetcode.com/problems/champagne-tower/discuss/?currentPage=1&orderBy=most_votes&query=
50
51// submission codes start here
52
53impl Solution {
54 pub fn champagne_tower(poured: i32, query_row: i32, query_glass: i32) -> f64 {
55 0f64
56 }
57}
58
59// submission codes end
60
61#[cfg(test)]
62mod tests {
63 use super::*;
64
65 #[test]
66 fn test_799() {
67 }
68}
69
Back
© 2025 bowen.ge All Rights Reserved.