AtCoder Beginner Contest 255 B

https://atcoder.jp/contests/abc255/tasks/abc255_b

f64でmax/minを取ろうとすると、

    points.iter().map(|&point| pt.dist(&point)).min().unwrap()

このように怒られます。

error[E0277]: the trait bound `f64: Ord` is not satisfied
    --> ABC255B2.rs:53:46
     |
53   |     points.iter().map(|&point| pt.dist(&point)).min().unwrap()
     |                                                 ^^^ the trait `Ord` is not implemented for `f64`

f64にはNaNがあるためOrdがないそうです。

    points.iter().map(|&point| pt.dist(&point)).
                    min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap()

とすればmax/minを取れます。

// Light It Up
#![allow(non_snake_case)]

use std::ops::Sub;


//////////////////// library ////////////////////

fn read<T: std::str::FromStr>() -> T {
    let mut line = String::new();
    std::io::stdin().read_line(&mut line).ok();
    line.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
            .map(|e| e.parse().ok().unwrap()).collect()
}


//////////////////// Point ////////////////////

#[derive(Clone, Copy)]
struct Point {
    x: i32,
    y: i32,
}

impl Sub for Point {
    type Output = Self;
    
    fn sub(self, other: Self) -> Self {
        Self { x: self.x - other.x, y: self.y - other.y }
    }
}

impl Point {
    fn dist(&self, other: &Point) -> f64 {
        let v = *self - *other;
        let x = v.x as f64;
        let y = v.y as f64;
        (x * x + y * y).sqrt()
    }
    
    fn read() -> Point {
        let v = read_vec();
        Point { x: v[0], y: v[1] }
    }
}


//////////////////// process ////////////////////

fn min_dist(pt: Point, points: &Vec<Point>) -> f64 {
    points.iter().map(|&point| pt.dist(&point)).
                    min_by(|a, b| a.partial_cmp(b).unwrap()).unwrap()
}

fn main() {
    let v = read_vec();
    let N: usize = v[0];
    let _K: usize = v[1];
    let A: Vec<usize> = read_vec();
    let points: Vec<Point> = (0..N).map(|_| Point::read()).collect();
    let source: Vec<Point> = A.iter().map(|&a| points[a-1]).collect();
    let R = points.iter().map(|&pt| min_dist(pt, &source)).
                    max_by(|a, b| a.partial_cmp(b).unwrap()).unwrap();
    println!("{}", R)
}