https://atcoder.jp/contests/math-and-algorithm/tasks/math_and_algorithm_ag
半径と中心間の距離の関係ですね。
// Two Circles #![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 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 //////////////////// type Circle = (Point, f64); fn read_input() -> Circle { let v = read_vec(); (Point { x: v[0], y: v[1] }, v[2]) } fn f(C1: Circle, C2: Circle) -> i32 { let d = (C1.0 - C2.0).mag(); if C1.1 > C2.1 + d || C2.1 > C1.1 + d { 1 } else if C1.1 == C2.1 + d || C2.1 == C1.1 + d { 2 } else if C1.1 + C2.1 == d { 4 } else if C1.1 + C2.1 < d { 5 } else { 3 } } fn main() { let C1 = read_input(); let C2 = read_input(); println!("{}", f(C1, C2)) }