結果

問題 No.306 さいたま2008
ユーザー lumc_
提出日時 2018-07-05 02:04:30
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 1,702 bytes
コンパイル時間 2,301 ms
コンパイル使用メモリ 79,716 KB
実行使用メモリ 56,320 KB
最終ジャッジ日時 2024-07-01 02:19:08
合計ジャッジ時間 6,575 ms
ジャッジサーバーID
(参考情報)
judge5 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 2
権限があれば一括ダウンロードができます

ソースコード

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(100));
    }
}
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(int x) {
        for(int i = 0; i < x; i++) {
            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;
            } else {
                right = midRight;
            }
        }

        return left;
    }
}
0