add cf round-1087-{A,B,C}.rs
This commit is contained in:
42
storage/cf/rs/round-1087-A.rs
Normal file
42
storage/cf/rs/round-1087-A.rs
Normal file
@@ -0,0 +1,42 @@
|
||||
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 t = iter.next().unwrap();
|
||||
(0..t).for_each(|_| {
|
||||
let (n, mut c, mut k) = (
|
||||
// number, combat power, k of flip flop
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
iter.next().unwrap(),
|
||||
);
|
||||
|
||||
let mut arr = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
|
||||
arr.sort();
|
||||
loop {
|
||||
let key = arr.binary_search(&c);
|
||||
match key {
|
||||
Ok(idx) => {
|
||||
c += arr[idx];
|
||||
arr.remove(idx);
|
||||
}
|
||||
Err(idx) => {
|
||||
if idx == 0 {
|
||||
break;
|
||||
} else {
|
||||
let delta = c - arr[idx - 1];
|
||||
let consume = if k >= delta { delta } else { k };
|
||||
k -= consume;
|
||||
c += consume + arr[idx - 1];
|
||||
arr.remove(idx - 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
println!("{}", c);
|
||||
});
|
||||
}
|
||||
37
storage/cf/rs/round-1087-B.rs
Normal file
37
storage/cf/rs/round-1087-B.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
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 t = iter.next().unwrap();
|
||||
(0..t).for_each(|_| {
|
||||
let n = iter.next().unwrap() as usize;
|
||||
let arr = (0..n).map(|_| iter.next().unwrap()).collect::<Vec<_>>();
|
||||
|
||||
// if n == 1 return 0
|
||||
for i in 0..n {
|
||||
if i == n - 1 {
|
||||
print!("{} ", 0);
|
||||
continue;
|
||||
}
|
||||
|
||||
let key = arr[i];
|
||||
|
||||
let mut cnt_lo = 0;
|
||||
let mut cnt_hi = 0;
|
||||
|
||||
for &e in arr[(i + 1)..n].iter() {
|
||||
if e > key {
|
||||
cnt_hi += 1;
|
||||
} else if e < key {
|
||||
cnt_lo += 1;
|
||||
}
|
||||
}
|
||||
print!("{} ", std::cmp::max(cnt_lo, cnt_hi));
|
||||
}
|
||||
println!();
|
||||
});
|
||||
}
|
||||
54
storage/cf/rs/round-1087-C.rs
Normal file
54
storage/cf/rs/round-1087-C.rs
Normal file
@@ -0,0 +1,54 @@
|
||||
use std::io::{Write, stdin, stdout};
|
||||
|
||||
fn client(n: usize) {
|
||||
let mut line = String::new();
|
||||
for i in 0..n - 1 {
|
||||
let left = 2 * i + 1;
|
||||
let right = 2 * i + 2;
|
||||
|
||||
println!("? {} {}", left, right);
|
||||
stdout().flush().unwrap();
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let q = line.trim().parse::<usize>().unwrap();
|
||||
if q == 1 {
|
||||
println!("! {}", left);
|
||||
stdout().flush().unwrap();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
println!("? {} {}", 2 * n - 1, 2 * n - 2);
|
||||
stdout().flush().unwrap();
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let q = line.trim().parse::<usize>().unwrap();
|
||||
if q == 1 {
|
||||
println!("! {}", 2 * n - 1);
|
||||
stdout().flush().unwrap();
|
||||
return;
|
||||
}
|
||||
println!("? {} {}", 2 * n - 1, 2 * n - 3);
|
||||
stdout().flush().unwrap();
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let q = line.trim().parse::<usize>().unwrap();
|
||||
if q == 1 {
|
||||
println!("! {}", 2 * n - 1);
|
||||
stdout().flush().unwrap();
|
||||
return;
|
||||
}
|
||||
println!("! {}", 2 * n);
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let mut line = String::new();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let t = line.trim().parse::<usize>().unwrap();
|
||||
(0..t).for_each(|_| {
|
||||
line.clear();
|
||||
stdin().read_line(&mut line).unwrap();
|
||||
let n = line.trim().parse::<usize>().unwrap();
|
||||
client(n);
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user