結果

問題 No.2555 Intriguing Triangle
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-12-02 01:18:40
言語 Rust
(1.77.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 2,424 bytes
コンパイル時間 1,931 ms
コンパイル使用メモリ 173,284 KB
実行使用メモリ 6,676 KB
最終ジャッジ日時 2023-12-02 01:18:53
合計ジャッジ時間 3,052 ms
ジャッジサーバーID
(参考情報)
judge12 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 1 ms
6,676 KB
testcase_01 AC 1 ms
6,676 KB
testcase_02 AC 1 ms
6,676 KB
testcase_03 AC 1 ms
6,676 KB
testcase_04 AC 2 ms
6,676 KB
testcase_05 AC 1 ms
6,676 KB
testcase_06 AC 1 ms
6,676 KB
testcase_07 AC 1 ms
6,676 KB
testcase_08 AC 1 ms
6,676 KB
testcase_09 AC 1 ms
6,676 KB
testcase_10 AC 1 ms
6,676 KB
testcase_11 AC 2 ms
6,676 KB
testcase_12 AC 1 ms
6,676 KB
testcase_13 AC 1 ms
6,676 KB
testcase_14 AC 2 ms
6,676 KB
testcase_15 AC 1 ms
6,676 KB
testcase_16 AC 1 ms
6,676 KB
testcase_17 AC 1 ms
6,676 KB
testcase_18 AC 1 ms
6,676 KB
testcase_19 AC 1 ms
6,676 KB
testcase_20 AC 2 ms
6,676 KB
testcase_21 AC 2 ms
6,676 KB
testcase_22 AC 1 ms
6,676 KB
testcase_23 AC 1 ms
6,676 KB
testcase_24 AC 1 ms
6,676 KB
testcase_25 AC 1 ms
6,676 KB
testcase_26 AC 1 ms
6,676 KB
testcase_27 AC 1 ms
6,676 KB
testcase_28 AC 1 ms
6,676 KB
testcase_29 AC 1 ms
6,676 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
warning: constant `epsilon` should have an upper case name
 --> Main.rs:1:7
  |
1 | const epsilon: f64 = 1e-9;
  |       ^^^^^^^ help: convert the identifier to upper case: `EPSILON`
  |
  = note: `#[warn(non_upper_case_globals)]` on by default

warning: 1 warning emitted

ソースコード

diff #

const epsilon: f64 = 1e-9;
fn main() {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut input_iter = input.split_whitespace();
    let de: i64 = input_iter.next().unwrap().parse().unwrap();

    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut input_iter = input.split_whitespace();
    let ab: i64 = input_iter.next().unwrap().parse().unwrap();

    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    let mut input_iter = input.split_whitespace();
    let ac: i64 = input_iter.next().unwrap().parse().unwrap();

    let mut res = false;
    for bd in 1..=100 {
        for ec in 1..=100 {
            if !can_triangle((bd + de + ec) as f64, ab as f64, ac as f64) {
                continue;
            }
            
            if let Some(dba) = angle(ac as f64, ab as f64, (bd + de + ec) as f64) {
            if let Some(eca) = angle(ab as f64, ac as f64, (bd + de + ec) as f64) {
            if let Some(ad) = length(ab as f64, bd as f64, dba) {
            if let Some(ae) = length(ac as f64, ec as f64, eca) {
                if !can_triangle(bd as f64, ab as f64, ad as f64) {
                    continue;
                }
                if !can_triangle(ec as f64, ac as f64, ae as f64) {
                    continue;
                }
                if let Some(bad) = angle(bd as f64, ab as f64, ad as f64) {
                if let Some(cae) = angle(ec as f64, ac as f64, ae as f64) {
                    if (bad - cae).abs() < epsilon {
                        res = true;
                    }
                }
                }
            }
            }
            }
            }
        }
    }
    println!("{}", if res {"Yes"} else {"No"});
}

fn angle(a: f64, b: f64, c: f64) -> Option<f64> {
    let cos = (b * b + c * c - a * a) / (2.0f64 * b * c);
    if cos.abs() > 1.0f64 {
        return None;
    }
    return Some(cos.acos());
}

fn length(b: f64, c: f64, cab: f64) -> Option<f64> {
    let axa = b * b + c * c - 2.0 * b * c * cab.cos();
    if axa < 0.0f64 {
        return None;
    }
    return Some(axa.sqrt());
}

fn can_triangle(a: f64, b: f64, c: f64) -> bool {
    return can_triangle0(a, b, c) || can_triangle0(c, a, b) || can_triangle0(b, c, a);
}

fn can_triangle0(a: f64, b: f64, c: f64) -> bool {
    return a >= b.max(c) && a < b + c;
}
0