20241015 finished.
This commit is contained in:
parent
0dac796b20
commit
b282d4c001
|
@ -263,4 +263,5 @@ mod p3162_find_the_number_of_good_pairs_i;
|
|||
mod p3164_find_the_number_of_good_pairs_ii;
|
||||
mod p3158_find_the_xor_of_numbers_which_appear_twice;
|
||||
mod p1884_egg_drop_with_2_eggs_and_n_floors;
|
||||
mod p887_super_egg_drop;
|
||||
mod p887_super_egg_drop;
|
||||
mod p3200_maximum_height_of_a_triangle;
|
52
src/problem/p3200_maximum_height_of_a_triangle.rs
Normal file
52
src/problem/p3200_maximum_height_of_a_triangle.rs
Normal file
|
@ -0,0 +1,52 @@
|
|||
/**
|
||||
* [3200] Maximum Height of a Triangle
|
||||
*/
|
||||
pub struct Solution {}
|
||||
|
||||
|
||||
// submission codes start here
|
||||
|
||||
impl Solution {
|
||||
pub fn max_height_of_triangle(red: i32, blue: i32) -> i32 {
|
||||
let mut result = 0;
|
||||
let mut row = 1;
|
||||
let mut switch = true;
|
||||
let (mut first_count, mut second_count) = (0, 0);
|
||||
|
||||
loop {
|
||||
if switch {
|
||||
first_count += row;
|
||||
} else {
|
||||
second_count += row;
|
||||
}
|
||||
|
||||
if first_count > red || second_count > blue {
|
||||
if second_count > red || first_count > blue {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
switch = !switch;
|
||||
row += 1;
|
||||
result += 1;
|
||||
}
|
||||
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
// submission codes end
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn test_3200() {
|
||||
assert_eq!(3, Solution::max_height_of_triangle(2, 4));
|
||||
assert_eq!(2, Solution::max_height_of_triangle(2, 1));
|
||||
assert_eq!(1, Solution::max_height_of_triangle(1, 1));
|
||||
assert_eq!(2, Solution::max_height_of_triangle(10, 1));
|
||||
assert_eq!(5, Solution::max_height_of_triangle(10, 10));
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user