Last active
January 16, 2018 14:07
-
-
Save AnthonyMikh/68cbd1c6e9d0fb7b5fdb1e69fff7f99b to your computer and use it in GitHub Desktop.
Решение задачи №61 от Unilecs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const SPEED_REGULAR_KMPH: i64 = 50; | |
const SPEED_CLEANUP_KMPH: i64 = 20; | |
type Point = (i64, i64); | |
struct Segment { | |
start: Point, | |
end: Point, | |
} | |
fn sqr (x: i64) -> i64 { | |
x * x | |
} | |
impl Segment { | |
fn hypot (&self) -> i64 { | |
let &Segment {start: (x1, y1), end: (x2, y2)} = self; | |
sqr(x1-x2) + sqr(y1-y2) | |
} | |
fn len (&self) -> f64 { | |
(self.hypot() as f64).sqrt() | |
} | |
} | |
fn calculate_cleanup_time (_: (i64, i64), segs: &[Segment]) -> f64 { | |
let total: f64 = segs.iter() | |
.map(|seg| seg.len() * 2.0) | |
.sum(); | |
total / 1000.0 / SPEED_CLEANUP_KMPH as f64 * 60.0 | |
} | |
fn main() { | |
let path = [ | |
Segment { start: (0, 0), end: (10000, 10000) }, | |
Segment { start: (5000, -10000), end: (5000, 10000) }, | |
Segment { start: (5000, 10000), end: (10000, 10000) } | |
]; | |
let start = (0, 0); | |
let answer = calculate_cleanup_time(start, &path).round() as u64; | |
assert_eq!(answer, 235) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Во второй ревизии убрано ненужное копирование