Řešení KSP úlohy 33-3-4 Obsazování území https://ksp.mff.cuni.cz/h/ulohy/33/zadani3.html#task-33-3-4
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

55 lines
1.9 KiB

use indicatif::{ProgressBar, ProgressStyle};
use std::collections::HashSet;
use main::{get_neighbors, House, City};
mod main;
fn main() {
// This is quite frankly useless
let city = City::read_from_file("01.in");
let bar = ProgressBar::new(city.get_house_count() as u64);
bar.set_style(ProgressStyle::default_bar()
.template("{spinner:.green} [{elapsed_precise}] [{bar:40.cyan/blue}] {pos}/{len} ({msg}) ({eta})")
.progress_chars("#>-"));
let mut useless_count = 0;
let mut checked_count = 0;
for y in 0..main::SIZE {
for x in 0..main::SIZE {
if city.is_house_xy(x, y) {
let house = House::new(x, y);
let house_neighbors = get_neighbors(&city, &house);
let mut useless = true;
for neighbor in &house_neighbors {
if city.get_price(&house) < city.get_price(&neighbor) {
useless = false;
break;
}
let neighbor_neighbors: HashSet<_> = get_neighbors(&city, &neighbor).into_iter().collect();
// Check if house_neighbors is a subset of neighbor_neighbors
let all_in = &house_neighbors.iter().all(|item| neighbor_neighbors.contains(item));
if !all_in {
useless = false;
break;
}
}
if useless {
println!("{} {}", y, x);
useless_count += 1;
} else {
//println!("Y{} X{} may be sometimes worth buying", y, x);
}
checked_count += 1;
bar.set_message(&*format!("{}, {:.2}%", useless_count, 100.0 * useless_count as f64/checked_count as f64));
bar.inc(1);
}
}
}
bar.finish();
}