結果

問題 No.306 さいたま2008
ユーザー haruteruharuteru
提出日時 2016-01-30 01:35:25
言語 C++11
(gcc 11.4.0)
結果
WA  
(最新)
AC  
(最初)
実行時間 -
コード長 1,520 bytes
コンパイル時間 495 ms
コンパイル使用メモリ 62,924 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 17:41:56
合計ジャッジ時間 1,300 ms
ジャッジサーバーID
(参考情報)
judge11 / judge9
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <math.h>

const long double INC_MIN = 0.0000000000001;

long double sqr(long double s)
{
    long double x = s / 2.0;
    long double last_x = 0.0;
    while (x != last_x) {
        last_x = x ;
        x = (x + s / x) / 2.0 ;
    }
    return x ;
}

long double pyt(long double sa, long double sb)
{
    return ::sqr((sa * sa) + (sb * sb));
}

long double f(long double ax, long double ay, long double bx, long double by)
{
    long double p_min = ay < by? ay: by;
    long double p_len = ::fabs(ay - by);
    long double p_max = p_min + p_len;
    long double rc = ax - p_max;
    long double wk = pyt(ax, p_len) + bx;
    long double inc = 1;
    long double n = 0;
    long double begin = 0;
    long double end = p_len;
    while (inc > INC_MIN) {
        n = begin;
        while (n <= end) {
            long double a = pyt(ax, (ay < by? n: (p_len - n)));
            long double b = pyt(bx, (by < ay? n: (p_len - n)));
            long double w = a + b;
            if (w < wk) {
                wk = w;
                rc = n;
            }
            n += inc;
        }
        if (rc >= (inc * 10)) begin = rc - (inc * 10);
        end = rc + (inc * 10);
        inc /= 10;
    }
    return p_min + rc;
}

int main()
{
    std::cout.precision(20);

    long double ax, ay, bx, by;
    std::cin >> ax;
    std::cin >> ay;
    std::cin >> bx;
    std::cin >> by;
    if (ay == by) std::cout << ay << std::endl;
    else std::cout << f(ax, ay, bx, by) << std::endl;
    return 0;
}
0