complete 2600.cpp 6906.cpp 4881.rs 24753.rs 34423.rs

This commit is contained in:
2026-01-22 23:39:54 -08:00
parent ffc4d85822
commit a52b20d5ed
5 changed files with 386 additions and 0 deletions

View File

@@ -0,0 +1,33 @@
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<usize>().unwrap());
let s = iter.next().unwrap();
let n = iter.next().unwrap();
let arr = (0..n).map(|_| iter.next().unwrap());
let mut seat_stat = vec![false; s];
for i in arr {
seat_stat[i - 1] = true;
}
let mut cnt = 0;
for i in 0..s {
if !seat_stat[i] {
let left = if i == 0 { s - 1 } else { i - 1 };
let right = (i + 1) % s;
if !seat_stat[left] && !seat_stat[right] {
seat_stat[i] = true;
cnt += 1;
}
}
}
println!("{}", cnt);
}

View File

@@ -0,0 +1,67 @@
use std::cmp::max;
use std::io::{read_to_string, stdin};
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<i64>().unwrap());
let (t0, t1, t2) = (
iter.next().unwrap(),
iter.next().unwrap(),
iter.next().unwrap(),
);
let ts = [[0, t0, t1], [t0, 0, t2], [t1, t2, 0]];
let n = iter.next().unwrap() as usize;
let pp = {
let mut pp = vec![vec![0; 3]; n];
for i in 0..3 {
for j in 0..n {
pp[j][i] = iter.next().unwrap();
}
}
pp
};
let mut dp = vec![vec![0; 3]; n];
dp[0][0] = pp[0][0];
dp[0][1] = pp[0][1];
dp[0][2] = pp[0][2];
for i in 1..n {
dp[i][0] = max(
dp[i - 1][0] + pp[i][0],
max(
dp[i - 1][1] + pp[i][0] - ts[1][0],
dp[i - 1][2] + pp[i][0] - ts[2][0],
),
);
dp[i][1] = max(
dp[i - 1][1] + pp[i][1],
max(
dp[i - 1][0] + pp[i][1] - ts[0][1],
dp[i - 1][2] + pp[i][1] - ts[2][1],
),
);
dp[i][2] = max(
dp[i - 1][2] + pp[i][2],
max(
dp[i - 1][0] + pp[i][2] - ts[0][2],
dp[i - 1][1] + pp[i][2] - ts[1][2],
),
);
}
let max_cost = dp[n - 1].iter().max().unwrap();
println!("{}", max_cost);
}

View File

@@ -0,0 +1,59 @@
use std::{
collections::HashMap,
io::{read_to_string, stdin},
u64,
};
fn transform(mut x: u64) -> u64 {
let mut s = 0;
while x > 0 {
let t = x % 10;
s += t * t;
x = x / 10;
}
s
}
fn main() {
let temp = read_to_string(stdin()).unwrap();
let mut iter = temp
.split_ascii_whitespace()
.map(|x| x.parse::<u64>().unwrap());
loop {
let mut dist_from_a: HashMap<u64, u64> = HashMap::new();
let mut dist_from_b: HashMap<u64, u64> = HashMap::new();
let (a, b) = (iter.next().unwrap(), iter.next().unwrap());
if a == 0 && b == 0 {
break;
}
let mut curr = a;
let mut step = 1;
while !dist_from_a.contains_key(&curr) {
dist_from_a.insert(curr, step);
curr = transform(curr);
step += 1;
}
curr = b;
step = 1;
while !dist_from_b.contains_key(&curr) {
dist_from_b.insert(curr, step);
curr = transform(curr);
step += 1;
}
let mut res = u64::MAX;
for (&n, &dist_a) in dist_from_a.iter() {
if let Some(dist_b) = dist_from_b.get(&n) {
res = res.min(dist_a + dist_b);
}
}
if res == u64::MAX {
res = 0;
}
println!("{} {} {}", a, b, res);
}
}