結果

問題 No.306 さいたま2008
ユーザー femtofemto
提出日時 2016-08-12 00:38:11
言語 C++14
(gcc 12.3.0 + boost 1.83.0)
結果
WA  
実行時間 -
コード長 705 bytes
コンパイル時間 676 ms
コンパイル使用メモリ 82,304 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-25 01:54:04
合計ジャッジ時間 1,446 ms
ジャッジサーバーID
(参考情報)
judge3 / judge5
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <iomanip>
#include <cmath>
using namespace std;

double x[2], y[2];
double f(double m) {
	return sqrt(x[0] * x[0] + (m - y[0]) * (m - y[0])) +
		sqrt(x[1] * x[1] + (m - y[1]) * (m - y[1]));
}

template<class Function>
double ternarySearch(double l, double r, Function f) {
	for(int i = 0; i < 200; i++) {
		double a = (l + l + r) / 3;
		double b = (l + r + r) / 3;
		if(f(a) > f(b)) l = a;
		else r = b;
	}
	return l;
}

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

	for(int i = 0; i < 2; i++) {
		cin >> x[i] >> y[i];
	}

	cout << ternarySearch(0, 1000, f) << endl;;
}
0