結果

問題 No.306 さいたま2008
ユーザー kichirb3kichirb3
提出日時 2018-03-24 22:52:09
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
AC  
実行時間 2 ms / 2,000 ms
コード長 1,375 bytes
コンパイル時間 684 ms
コンパイル使用メモリ 75,916 KB
実行使用メモリ 4,384 KB
最終ジャッジ日時 2023-09-07 08:59:33
合計ジャッジ時間 1,609 ms
ジャッジサーバーID
(参考情報)
judge11 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// No.306 さいたま2008
// https://yukicoder.me/problems/no/306
//

#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;

long double solve(long double ax, long double ay, long double bx, long double by);
long double calc_dist(long double ax, long double ay, long double bx, long double by, long double py);


int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);

    long double ax, ay, bx, by;
    cin >> ax >> ay >> bx >> by;
    long double ans = solve(ax, ay, bx, by);
    cout << fixed << setprecision(10) << ans << endl;
}

long double solve(long double ax, long double ay, long double bx, long double by) {
    long double uy = max(ay, by);
    long double ly = min(ay, by);

    for (auto i = 0; i < 100; ++i) {
        long double py1 = (ly * 2 + uy) / 3;
        long double mid1_dist = calc_dist(ax, ay, bx, by, py1);
        long double py2 = (ly + uy * 2) / 3;
        long double mid2_dist = calc_dist(ax, ay, bx, by, py2);

        if (mid2_dist > mid1_dist)
            uy = py2;
        else
            ly = py1;
    }

    return (uy + ly) / 2;
}

long double calc_dist(long double ax, long double ay, long double bx, long double by, long double py) {
    long double ap = sqrt((ax*ax + (ay-py)*(ay-py)));
    long double bp = sqrt((bx*bx + (by-py)*(by-py)));
    return ap + bp;
}
0