https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_af
総当たりでOKですね。
f64はminを取るのが面倒で、foldを使えば可能ですが、
fold(f64::MAX, f64::min)
がAtCoderでは通らなくて、f64::MAXの代わりに1e7としました。
// Nearest Points #![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)] #[derive(Debug)] struct Point { x: f64, y: f64, } 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 read() -> Point { let v = read_vec(); Point { x: v[0], y: v[1] } } fn inner_product(v: &Point, w: &Point) -> f64 { v.x * w.x + v.y * w.y } fn mag(&self) -> f64 { Point::inner_product(self, self).sqrt() } } //////////////////// process //////////////////// fn read_input() -> Vec<Point> { let N: usize = read(); (0..N).map(|_| Point::read()).collect::<Vec<Point>>() } fn f(pts: Vec<Point>) -> f64 { let N = pts.len(); (0..N).map(|i| (i+1..N).map(|j| (pts[i] - pts[j]).mag()). fold(1e7, f64::min)). fold(1e7, f64::min) // fold(f64::MAX, f64::min)). // fold(f64::MAX, f64::min) } fn main() { let pts = read_input(); println!("{}", f(pts)) }