結果

問題 No.2555 Intriguing Triangle
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-12-01 20:51:21
言語 Java21
(openjdk 21)
結果
WA  
実行時間 -
コード長 2,355 bytes
コンパイル時間 3,598 ms
コンパイル使用メモリ 79,220 KB
実行使用メモリ 60,104 KB
最終ジャッジ日時 2023-12-01 20:51:33
合計ジャッジ時間 9,292 ms
ジャッジサーバーID
(参考情報)
judge11 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 142 ms
58,080 KB
testcase_01 WA -
testcase_02 WA -
testcase_03 WA -
testcase_04 WA -
testcase_05 AC 142 ms
58,080 KB
testcase_06 AC 138 ms
57,552 KB
testcase_07 AC 139 ms
58,176 KB
testcase_08 AC 140 ms
57,568 KB
testcase_09 AC 141 ms
57,960 KB
testcase_10 AC 148 ms
58,208 KB
testcase_11 AC 150 ms
58,060 KB
testcase_12 AC 154 ms
58,080 KB
testcase_13 AC 153 ms
58,088 KB
testcase_14 AC 153 ms
58,072 KB
testcase_15 AC 148 ms
57,820 KB
testcase_16 AC 143 ms
58,224 KB
testcase_17 AC 139 ms
57,928 KB
testcase_18 WA -
testcase_19 AC 136 ms
57,836 KB
testcase_20 AC 166 ms
59,920 KB
testcase_21 AC 150 ms
60,104 KB
testcase_22 WA -
testcase_23 AC 140 ms
58,088 KB
testcase_24 AC 139 ms
57,712 KB
testcase_25 AC 141 ms
58,188 KB
testcase_26 AC 141 ms
58,080 KB
testcase_27 AC 148 ms
56,248 KB
testcase_28 AC 147 ms
57,800 KB
testcase_29 AC 144 ms
57,948 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Optional;
import java.util.Scanner;

public class Main {
    private static final double epsilon = 1e-9;

    public static void main(String[] args) {
        try (Scanner in = new Scanner(System.in)) {
            int de = in.nextInt();
            int ab = in.nextInt();
            // d
            // e
            int ac = in.nextInt();

            boolean res = false;
            for (int bd = 1; bd <= 100; bd++) {
                for (int ec = 1; ec <= 100; ec++) {
                    if (bd + de + ec >= ab + ac) {
                        break;
                    }

                    Optional<Double> cos_dba = cosine_formula(ac, ab, bd + de + ec);
                    Optional<Double> cos_eca = cosine_formula(ab, ac, bd + de + ec);
                    if (cos_dba.isEmpty() || cos_eca.isEmpty()) {
                        continue;
                    }
                    double dba = Math.acos(cos_dba.get().doubleValue());
                    double eca = Math.acos(cos_eca.get().doubleValue());

                    double ad = Math.sqrt(cosine_formula2(ab, bd, dba));
                    double ae = Math.sqrt(cosine_formula2(ac, ec, eca));

                    Optional<Double> cos_bad = cosine_formula(bd, ab, ad);
                    Optional<Double> cos_cae = cosine_formula(ec, ac, ae);
                    if (cos_bad.isEmpty() || cos_cae.isEmpty()) {
                        continue;
                    }
                    double bad = Math.acos(cos_bad.get().doubleValue());
                    double cae = Math.acos(cos_cae.get().doubleValue());

//                    Utils.debug(de, ab, ac, bd, ec, dba, eca, ad, ae, bad, cae, Math.abs(bad - cae) < 1e-3);
                    if (Math.abs(bad - cae) < epsilon) {
                        res = true;
                    }
                }
            }
            System.out.println(res ? "Yes" : "No");
        }
    }

    private static final Optional<Double> cosine_formula(double a, double b, double c) {
        double cos = (b * b + c * c - a * a) / (2.0d * b * c);
        if (Math.abs(cos) > 1.0d) {
            return Optional.empty();
        }
        return Optional.of(cos);
    }

    private static final double cosine_formula2(double b, double c, double cab) {
        return b * b + c * c - 2.0 * b * c * Math.cos(cab);
    }
}
0