-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathamrandpins.rs
51 lines (47 loc) · 1.31 KB
/
amrandpins.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
struct Scan {
buffer: std::collections::VecDeque<String>,
}
impl Scan {
fn new() -> Scan {
Scan {
buffer: std::collections::VecDeque::new(),
}
}
fn next<T: std::str::FromStr>(&mut self) -> T {
loop {
if let Some(token) = self.buffer.pop_front() {
break token.parse::<T>().ok().unwrap();
}
let mut line = String::new();
std::io::stdin().read_line(&mut line).expect("Fail to read");
self.buffer = line.split_whitespace().map(String::from).collect();
}
}
}
fn _main() {
let mut scan = Scan::new();
let r: i64 = scan.next();
let x: i64 = scan.next();
let y: i64 = scan.next();
let xp: i64 = scan.next();
let yp: i64 = scan.next();
// steps = ceil(d/(2*r))
// we could avoid floating points by using squares
// steps^2 = d^2/(2*r)^2
// steps^2*(2*r)^2 = d^2
// and then use binary search to solve it
let d = (((x - xp) * (x - xp) + (y - yp) * (y - yp)) as f64).sqrt();
let mut steps = d as i64 / (2 * r);
if ((steps * 2 * r) as f64) < d {
steps += 1;
}
println!("{}", steps);
}
fn main() {
std::thread::Builder::new()
.stack_size(1 << 23)
.spawn(_main)
.unwrap()
.join()
.unwrap();
}