結果

問題 No.306 さいたま2008
ユーザー YamaKasaYamaKasa
提出日時 2018-09-17 00:25:21
言語 Java21
(openjdk 21)
結果
AC  
実行時間 142 ms / 2,000 ms
コード長 1,669 bytes
コンパイル時間 3,240 ms
コンパイル使用メモリ 73,660 KB
実行使用メモリ 56,468 KB
最終ジャッジ日時 2023-09-25 09:15:41
合計ジャッジ時間 6,728 ms
ジャッジサーバーID
(参考情報)
judge14 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 130 ms
56,132 KB
testcase_01 AC 132 ms
55,892 KB
testcase_02 AC 133 ms
56,208 KB
testcase_03 AC 134 ms
56,208 KB
testcase_04 AC 127 ms
55,788 KB
testcase_05 AC 133 ms
56,252 KB
testcase_06 AC 135 ms
56,468 KB
testcase_07 AC 131 ms
55,648 KB
testcase_08 AC 129 ms
55,948 KB
testcase_09 AC 131 ms
56,260 KB
testcase_10 AC 136 ms
56,168 KB
testcase_11 AC 138 ms
56,008 KB
testcase_12 AC 137 ms
55,964 KB
testcase_13 AC 134 ms
55,900 KB
testcase_14 AC 132 ms
55,876 KB
testcase_15 AC 133 ms
56,356 KB
testcase_16 AC 134 ms
56,208 KB
testcase_17 AC 135 ms
56,304 KB
testcase_18 AC 137 ms
56,236 KB
testcase_19 AC 136 ms
56,012 KB
testcase_20 AC 142 ms
55,940 KB
testcase_21 AC 133 ms
56,212 KB
testcase_22 AC 133 ms
56,012 KB
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.Scanner;

public class Main {
	static double xa;
	static double ya;
	static double xb;
	static double yb;
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		xa = scan.nextDouble();
		ya = scan.nextDouble();
		xb = scan.nextDouble();
		yb = scan.nextDouble();
		scan.close();
		double yp = 9;
		double r = Math.max(ya, yb);
		double l = Math.min(ya, yb);
		while(Math.abs(r - l) > 0.000001) {
			double y1 = (2.0 * l + r) / 3.0;
			double y2 = (l + 2.0 * r) / 3.0;
//			System.out.println(l + " " + r);
//			System.out.println(y1 + " " + y2);
//			System.out.println(diff1_func(y1) + " " + diff1_func(y2));
//			System.out.println();
			if(Math.abs(diff1_func(y1)) < Math.abs(diff1_func(y2))) {
				r = y2;
			}else {
				l = y1;
			}
		}

		yp = (l + r) / 2.0;
		System.out.println(yp);
		System.exit(0);
		for(int i = 0; i < 100; i++) {
			double yp_new = yp - diff1_func(yp) / diff2_func(yp);
			yp = yp_new;
			System.out.println(yp);
		}
		System.out.println(yp);
	}
	static double func(double yp) {
		return Math.pow(func1(yp), 0.5) +  Math.pow(func2(yp), 0.5);
	}
	static double diff1_func(double yp) {
		return (yp - ya) * Math.pow(xa * xa + (yp - ya) * (yp - ya), -0.5)
				+ (yp - yb) * Math.pow(xb * xb + (yp - yb) * (yp - yb), -0.5);
	}
	static double diff2_func(double yp) {
		return Math.pow(func1(yp), -0.5) - Math.pow(yp - ya, 2) * Math.pow(func1(yp), -1.5) +
				Math.pow(func2(yp), -0.5) - Math.pow(yp - yb, 2)* Math.pow(func2(yp), -1.5);
	}
	static double func1(double yp) {
		return xa * xa + (yp - ya) * (yp - ya);
	}
	static double func2(double yp) {
		return xb * xb + (yp - yb) * (yp - yb);
	}
}
0