結果

問題 No.306 さいたま2008
コンテスト
ユーザー chuka231
提出日時 2015-11-27 23:24:51
言語 C++11
(gcc 15.2.0 + boost 1.89.0)
コンパイル:
g++-15 -O2 -lm -std=gnu++11 -Wuninitialized -DONLINE_JUDGE -o a.out _filename_
実行:
./a.out
結果
WA  
実行時間 -
コード長 769 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 381 ms
コンパイル使用メモリ 71,276 KB
実行使用メモリ 6,400 KB
最終ジャッジ日時 2026-04-04 09:08:21
合計ジャッジ時間 13,333 ms
ジャッジサーバーID
(参考情報)
judge4_0 / judge3_0
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 11 WA * 15
権限があれば一括ダウンロードができます
コンパイルメッセージ
In file included from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/ostream:42,
                 from /home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/iostream:43,
                 from main.cpp:1:
In member function 'std::basic_ostream<_CharT, _Traits>::__ostream_type& std::basic_ostream<_CharT, _Traits>::operator<<(double) [with _CharT = char; _Traits = std::char_traits<char>]',
    inlined from 'int main()' at main.cpp:45:11:
/home/linuxbrew/.linuxbrew/Cellar/gcc/15.2.0_1/include/c++/15/bits/ostream.h:232:25: warning: 'ans' may be used uninitialized [-Wmaybe-uninitialized]
  232 |       { return _M_insert(__f); }
      |                ~~~~~~~~~^~~~~
main.cpp: In function 'int main()':
main.cpp:38:24: note: 'ans' was declared here
   38 |                 double ans;
      |                        ^~~

ソースコード

diff #
raw source code

#include <iostream>
#include <string>
using namespace std;

double min(double a, double b)
{
	if (a > b) return b;
	else return a;
}
double max(double a, double b)
{
	if (a < b) return b;
	else return a;
}

int main()
{
	double ax, ay, bx, by;
	double p;

	cin >> ax >> ay;
	cin >> bx >> by;

	if (ax == bx && ay == by) {
		cout << ay << endl;
		return 0;
	}
	else if (ax == bx) {
		cout << (ay + by) / 2 << endl;
		return 0;
	}
	else if (ay == by) {
		cout << ay << endl;
		return 0;
	}
	else {
		double tmp = 10000000;
		double ans;
		for (p = min(ay, by); p < max(ay, by); p += 0.000001) {
			if (tmp >(ay - p)*(ay - p) + (by - p)*(by - p)) {
				tmp = (ay - p)*(ay - p) + (by - p)*(by - p);
				ans = p;
			}
		}
		cout << ans << endl;
		return 0;
	}

	return 0;
}
0