結果

問題 No.306 さいたま2008
ユーザー lumc_lumc_
提出日時 2018-07-05 02:02:41
言語 Java21
(openjdk 21)
結果
TLE  
実行時間 -
コード長 1,719 bytes
コンパイル時間 2,133 ms
コンパイル使用メモリ 77,300 KB
実行使用メモリ 65,292 KB
最終ジャッジ日時 2023-09-13 17:38:28
合計ジャッジ時間 8,651 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
testcase_21 -- -
testcase_22 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;
import java.util.function.DoubleUnaryOperator;
import java.lang.Math;

/**
 * @Problems https://yukicoder.me/problems/no/306
 */
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        double x1 = sc.nextDouble(), y1 = sc.nextDouble(), x2 = sc.nextDouble(), y2 = sc.nextDouble();
        Sanbun s = new Sanbun(0, 1000);
        s.setFunction(y -> {
            double sa1 = Math.abs(y - y1);
            double sa2 = Math.abs(y - y2);
            return Math.sqrt(x1*x1+sa1*sa1)+Math.sqrt(x2*x2+sa2*sa2);
        });
        System.out.println(s.run());
    }
}
class Sanbun {
    private double left, right;
    private DoubleUnaryOperator function;
    private double gosa = 0.00000001;

    public Sanbun(double left, double right) {
        this.left = left;
        this.right = right;
    }

    public Sanbun(double left, double right, DoubleUnaryOperator function) {
        this(left, right);
        this.function = function;
    }

    private double calc(double value) {
        return function.applyAsDouble(value);
    }

    public void setFunction(DoubleUnaryOperator function) {
        this.function = function;
    }

    public double run() {
        while (Math.abs(left - right) > gosa) {
            double midLeft = left + (right - left) / 3;
            double midRight = right - (right - left) / 3;
            double midLeftResult = calc(midLeft);
            double midRightResult = calc(midRight);
            if (midLeftResult > midRightResult) {
                left = midLeft - gosa;
            } else {
                right = midRight + gosa;
            }
        }

        return left;
    }
}
0