結果

問題 No.306 さいたま2008
ユーザー btk
提出日時 2015-11-28 00:17:21
言語 C++11(廃止可能性あり)
(gcc 13.3.0)
結果
AC  
実行時間 7 ms / 2,000 ms
コード長 873 bytes
コンパイル時間 1,363 ms
コンパイル使用メモリ 158,124 KB
実行使用メモリ 6,820 KB
最終ジャッジ日時 2025-02-14 12:10:41
合計ジャッジ時間 2,405 ms
ジャッジサーバーID
(参考情報)
judge2 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 26
権限があれば一括ダウンロードができます

ソースコード

diff #

#include <bits/stdc++.h>
using namespace std;
#define F __float128
const F eps=1e-20;

F Xa,Xb,Ya,Yb;
inline F sqrt(F x){
    F top=x;
    F bottom=0;
    while(top-bottom>eps){
        F m=(top+bottom)/2;
        if(m*m>x)top=m;
        else bottom=m;
    }
    return bottom;
}

inline F calc(F yy){
    F t=Yb-yy;
    F l=yy-Ya;
    return sqrt(Xb*Xb+t*t)+sqrt(Xa*Xa+l*l);
}
int main() {
    cout<<setprecision(10);
    cout<<fixed;
    double xa,ya,xb,yb;
    cin>>xa>>ya>>xb>>yb;
    if(ya>yb){
        swap(xa,xb);
        swap(ya,yb);
    }
    Xa=xa;
    Ya=ya;
    Xb=xb;
    Yb=yb;
    {
        F top=Yb;
        F bottom=Ya;
        while(top-bottom>eps){
            F m1=(top*2+bottom)/3;
            F m2=(top+bottom*2)/3;
            if(calc(m1)<calc(m2))bottom=m2;
            else top=m1;
        }
        cout<<(double)top<<endl;
    }

    return 0;
}
0