結果

問題 No.2555 Intriguing Triangle
ユーザー EvbCFfp1XBEvbCFfp1XB
提出日時 2023-12-02 00:05:56
言語 Java21
(openjdk 21)
結果
AC  
実行時間 170 ms / 2,000 ms
コード長 3,171 bytes
コンパイル時間 9,217 ms
コンパイル使用メモリ 79,128 KB
実行使用メモリ 60,036 KB
最終ジャッジ日時 2023-12-02 00:06:12
合計ジャッジ時間 7,561 ms
ジャッジサーバーID
(参考情報)
judge15 / judge12
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 133 ms
57,840 KB
testcase_01 AC 132 ms
57,840 KB
testcase_02 AC 130 ms
57,832 KB
testcase_03 AC 132 ms
57,824 KB
testcase_04 AC 121 ms
56,824 KB
testcase_05 AC 118 ms
56,704 KB
testcase_06 AC 132 ms
57,720 KB
testcase_07 AC 139 ms
57,836 KB
testcase_08 AC 134 ms
56,012 KB
testcase_09 AC 138 ms
57,960 KB
testcase_10 AC 147 ms
58,088 KB
testcase_11 AC 145 ms
58,244 KB
testcase_12 AC 151 ms
57,960 KB
testcase_13 AC 146 ms
57,836 KB
testcase_14 AC 146 ms
57,828 KB
testcase_15 AC 170 ms
57,984 KB
testcase_16 AC 133 ms
58,084 KB
testcase_17 AC 129 ms
57,968 KB
testcase_18 AC 129 ms
56,816 KB
testcase_19 AC 131 ms
57,856 KB
testcase_20 AC 149 ms
59,848 KB
testcase_21 AC 149 ms
60,036 KB
testcase_22 AC 120 ms
56,688 KB
testcase_23 AC 155 ms
56,008 KB
testcase_24 AC 133 ms
56,144 KB
testcase_25 AC 134 ms
57,948 KB
testcase_26 AC 139 ms
57,840 KB
testcase_27 AC 143 ms
58,072 KB
testcase_28 AC 132 ms
57,852 KB
testcase_29 AC 136 ms
58,060 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 (!can_triangle(bd + de + ec, ab, ac)) {
                        continue;
                    }

                    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());

                    Optional<Double> adxad = cosine_formula2(ab, bd, dba);
                    Optional<Double> aexae = cosine_formula2(ac, ec, eca);
                    if (adxad.isEmpty() || aexae.isEmpty()) {
                        continue;
                    }
                    double ad = Math.sqrt(adxad.get().doubleValue());
                    double ae = Math.sqrt(aexae.get().doubleValue());

                    if (!can_triangle(bd, ab, ad)) {
                        continue;
                    }
                    if (!can_triangle(ec, ac, ae)) {
                        continue;
                    }

                    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());

                    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 Optional<Double> cosine_formula2(double b, double c, double cab) {
        double axa = b * b + c * c - 2.0 * b * c * Math.cos(cab);
        if (axa < 0d) {
            return Optional.empty();
        }
        return Optional.of(axa);
    }

    private static final boolean can_triangle(double a, double b, double c) {
        return can_triangle0(a, b, c) || can_triangle0(c, a, b) || can_triangle0(b, c, a);
    }

    private static final boolean can_triangle0(double a, double b, double c) {
        return a >= Math.max(b, c) && a < b + c;
    }
}
0