結果

問題 No.306 さいたま2008
ユーザー tsunabit
提出日時 2020-03-27 02:13:14
言語 Java
(openjdk 23)
結果
WA  
実行時間 -
コード長 896 bytes
コンパイル時間 3,315 ms
コンパイル使用メモリ 79,604 KB
実行使用メモリ 54,504 KB
最終ジャッジ日時 2025-01-02 07:49:22
合計ジャッジ時間 6,904 ms
ジャッジサーバーID
(参考情報)
judge3 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 21 WA * 2
権限があれば一括ダウンロードができます

ソースコード

diff #

import java.util.*;
import java.io.*;
import java.math.*;

public class No306 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int xa=sc.nextInt(), ya=sc.nextInt(),xb=sc.nextInt(), yb=sc.nextInt();
//		double t = yb, b = ya;
//		double t = ya, b = yb;
		double t, b;
		if(ya > yb) {
			t = ya;
			b = yb;
		}else {
			t = yb;
			b = ya;
		}
		while(t-b > 0.000001) {
			double p0 = (t*2+b)/3;
			double p1 = (t+b*2)/3;
			if(search(xa,ya,xb,yb,p0) < search(xa,ya,xb,yb,p1)) {
				b = p1;
			}else {
				t = p0;
			}
		}
		
		if(search(xa,ya,xb,yb,t) < search(xa,ya,xb,yb,b)) {
			System.out.println(t);
		}else {
			System.out.println(b);
		}
 	}
	public static double search(int xa, int ya, int xb, int yb, double p) {
		double a = Math.sqrt(Math.pow(xa, 2) + Math.pow(ya-p, 2));
		double b = Math.sqrt(Math.pow(xb, 2) + Math.pow(yb-p, 2));
		return a+b;
	}
}
0