結果

問題 No.306 さいたま2008
ユーザー haruteruharuteru
提出日時 2016-01-29 12:57:51
言語 C++11
(gcc 11.4.0)
結果
WA  
実行時間 -
コード長 872 bytes
コンパイル時間 498 ms
コンパイル使用メモリ 62,880 KB
実行使用メモリ 4,348 KB
最終ジャッジ日時 2023-10-21 16:35:13
合計ジャッジ時間 1,365 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

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

double f(double ax, double ay, double bx, double by)
{
    if (ay == by) {
        return ay;
    }

    double p_min = ay < by? ay: by;
    double p_len = ::fabs(ay - by);
    double p_max = p_min + p_len;
    double n  = 0;
    double rc = ax;
    double wk = pyt(ax, p_len) + bx;
    while (n <= p_len) {
        double a = pyt(ax, (ay < by? n: (p_len - n)));
        double b = pyt(bx, (by < ay? n: (p_len - n)));
        double w = a + b;
        if (w < wk) {
            wk = w;
            rc = n;
        }
        n += 0.001;
    }
    return p_min + rc;
}

int main()
{
    double ax, ay, bx, by;
    std::cin >> ax;
    std::cin >> ay;
    std::cin >> bx;
    std::cin >> by;
    std::cout << f(ax, ay, bx, by) << std::endl;
    return 0;
}
0