20241024 finished.

This commit is contained in:
2024-10-24 09:08:13 +08:00
parent 3102da99a8
commit bce8de1c85
266 changed files with 2321 additions and 2014 deletions

View File

@@ -1,3 +1,3 @@
mod problem1;
mod problem2;
mod problem3;
mod problem3;

View File

@@ -12,4 +12,4 @@ impl Solution {
result
}
}
}

View File

@@ -1,13 +1,13 @@
pub struct Solution;
use std::collections::BinaryHeap;
use std::cmp::Reverse;
use std::collections::BinaryHeap;
impl Solution {
pub fn min_operations(nums: Vec<i32>, k: i32) -> i32 {
let mut heap = BinaryHeap::new();
let k = k as i64;
for i in nums {
let i = i as i64;
heap.push(Reverse(i));
@@ -23,7 +23,6 @@ impl Solution {
result += 1;
}
result
}
}
}

View File

@@ -5,7 +5,7 @@ use std::collections::HashMap;
impl Solution {
pub fn count_pairs_of_connectable_servers(edges: Vec<Vec<i32>>, signal_speed: i32) -> Vec<i32> {
let n = edges.len();
let mut graph = vec![vec![];n];
let mut graph = vec![vec![]; n];
let signal_speed = signal_speed as i64;
for edge in &edges {
@@ -17,17 +17,22 @@ impl Solution {
graph[y].push((x, weight));
}
let mut connection = vec![(0,0);n];
for next in &graph[0] {
}
let mut connection = vec![(0, 0); n];
for next in &graph[0] {}
let mut result = Vec::with_capacity(n);
result
}
fn dfs(graph: &Vec<Vec<(usize, i64)>>, conection: &mut Vec<(i64, usize)>, now: usize, pre: usize, distance: i64, start: usize) {
fn dfs(
graph: &Vec<Vec<(usize, i64)>>,
conection: &mut Vec<(i64, usize)>,
now: usize,
pre: usize,
distance: i64,
start: usize,
) {
for next in &graph[now] {
if next.0 == pre {
continue;
@@ -39,8 +44,14 @@ impl Solution {
}
}
fn tree_dp(graph: &Vec<Vec<(usize, i64)>>, conection: &mut Vec<(i64, usize)>, result: &mut Vec<i32>,
now: usize, pre: usize, signal_speed: i64) {
fn tree_dp(
graph: &Vec<Vec<(usize, i64)>>,
conection: &mut Vec<(i64, usize)>,
result: &mut Vec<i32>,
now: usize,
pre: usize,
signal_speed: i64,
) {
let mut count = HashMap::new();
for node in conection {
@@ -68,4 +79,4 @@ impl Solution {
}
}
}
}
}