Submission #2012449


Source Code Expand

#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::{stdin, stdout, BufWriter, Write};
mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;
    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }
    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}
#[allow(unused_macros)]
macro_rules ! get { ( $ t : ty ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . trim ( ) . parse ::<$ t > ( ) . unwrap ( ) } } ; ( $ ( $ t : ty ) ,* ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; let mut iter = line . split_whitespace ( ) ; ( $ ( iter . next ( ) . unwrap ( ) . parse ::<$ t > ( ) . unwrap ( ) , ) * ) } } ; ( $ t : ty ; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ t ) ) . collect ::< Vec < _ >> ( ) } ; ( $ ( $ t : ty ) ,*; $ n : expr ) => { ( 0 ..$ n ) . map ( | _ | get ! ( $ ( $ t ) ,* ) ) . collect ::< Vec < _ >> ( ) } ; ( $ t : ty ;; ) => { { let mut line : String = String :: new ( ) ; stdin ( ) . read_line ( & mut line ) . unwrap ( ) ; line . split_whitespace ( ) . map ( | t | t . parse ::<$ t > ( ) . unwrap ( ) ) . collect ::< Vec < _ >> ( ) } } ; }
#[allow(unused_macros)]
macro_rules ! debug { ( $ ( $ a : expr ) ,* ) => { println ! ( concat ! ( $ ( stringify ! ( $ a ) , " = {:?}, " ) ,* ) , $ ( $ a ) ,* ) ; } }

fn dist((x1, y1): (f64, f64), (x2, y2): (f64, f64)) -> f64 {
    f64::sqrt((x1 - x2).powi(2) + (y1 - y2).powi(2))
}

fn angle((x1, y1): (f64, f64), (x2, y2): (f64, f64), (x3, y3): (f64, f64)) -> f64 {
    let (vx1, vy1) = (x1 - x2, y1 - y2);
    let (vx2, vy2) = (x3 - x2, y3 - y2);

    f64::acos(
        (vx1 * vx2 + vy1 * vy2).abs()
            / (f64::sqrt(vx1 * vx1 + vy1 * vy1) * f64::sqrt(vx2 * vx2 + vy2 * vy2)),
    )
}

fn check(r: f64, l1: f64, l2: f64, l3: f64, a1: f64, a2: f64) -> bool {
    let x = r / f64::sin(a1 / 2.0) * f64::cos(a1 / 2.0);
    let y = r / f64::sin(a2 / 2.0) * f64::cos(a2 / 2.0);

    l1 >= 2.0 * r + x + y && l2 >= x && l3 >= y
}

fn main() {
    let a = get!(f64, f64);
    let b = get!(f64, f64);
    let c = get!(f64, f64);

    let mut l = 0.0;
    let mut r = 1000.0;

    for _ in 0..1000 {
        let mid = (l + r) / 2.0;

        if check(
            mid,
            dist(a, b),
            dist(a, c),
            dist(b, c),
            angle(c, a, b),
            angle(a, b, c),
        )
            || check(
                mid,
                dist(a, c),
                dist(b, c),
                dist(a, b),
                angle(a, c, b),
                angle(b, a, c),
            )
            || check(
                mid,
                dist(b, c),
                dist(a, b),
                dist(a, c),
                angle(c, b, a),
                angle(a, c, b),
            ) {
            l = mid;
        } else {
            r = mid;
        }
    }

    println!("{}", (l + r) / 2.0);
}

Submission Info

Submission Time
Task B - Inscribed Bicycle
User hatoo
Language Rust (1.15.1)
Score 500
Code Size 3649 Byte
Status AC
Exec Time 9 ms
Memory 4604 KB

Judge Result

Set Name Sample All
Score / Max Score 0 / 0 500 / 500
Status
AC × 2
AC × 18
Set Name Test Cases
Sample example0.txt, example1.txt
All 000.txt, 001.txt, 002.txt, 003.txt, 004.txt, 005.txt, 006.txt, 007.txt, 008.txt, 009.txt, 010.txt, 011.txt, 012.txt, 013.txt, 014.txt, 015.txt, example0.txt, example1.txt
Case Name Status Exec Time Memory
000.txt AC 9 ms 4604 KB
001.txt AC 2 ms 4352 KB
002.txt AC 2 ms 4352 KB
003.txt AC 2 ms 4352 KB
004.txt AC 2 ms 4352 KB
005.txt AC 2 ms 4352 KB
006.txt AC 2 ms 4352 KB
007.txt AC 2 ms 4352 KB
008.txt AC 2 ms 4352 KB
009.txt AC 2 ms 4352 KB
010.txt AC 2 ms 4352 KB
011.txt AC 2 ms 4352 KB
012.txt AC 2 ms 4352 KB
013.txt AC 2 ms 4352 KB
014.txt AC 2 ms 4352 KB
015.txt AC 2 ms 4352 KB
example0.txt AC 2 ms 4352 KB
example1.txt AC 2 ms 4352 KB