結果

問題 No.450 ベー君のシャトルラン
コンテスト
ユーザー くれちー
提出日時 2016-12-01 01:51:40
言語 C90(gcc12)
(gcc 12.4.0)
コンパイル:
gcc-12 -O2 -std=c90 -DONLINE_JUDGE -o a.out _filename_ -lm
実行:
./a.out
結果
WA  
実行時間 -
コード長 952 bytes
記録
記録タグの例:
初AC ショートコード 純ショートコード 純主流ショートコード 最速実行時間
コンパイル時間 194 ms
コンパイル使用メモリ 30,752 KB
最終ジャッジ日時 2026-02-23 23:02:31
ジャッジサーバーID
(参考情報)
judge1 / judge2
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 1 WA * 2
other AC * 10 TLE * 1 -- * 9
権限があれば一括ダウンロードができます
コンパイルメッセージ
main.c: In function ‘main’:
main.c:14:9: warning: ignoring return value of ‘scanf’ declared with attribute ‘warn_unused_result’ [-Wunused-result]
   14 |         scanf("%lf %lf %lf %lf", &vl, &vr, &d, &w);
      |         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

ソースコード

diff #
raw source code

#include <stdio.h>
#include <math.h>

double px(double a1, double b1, double a2, double b2) {
	return (b2 - b1) / (a1 - a2);
}

double py(double a1, double b1, double a2, double b2) {
	return a1 * px(a1, b1, a2, b2) + b1;
}

int main() {
	double vl, vr, d, w;
	scanf("%lf %lf %lf %lf", &vl, &vr, &d, &w);

	double x1, y1, x2, y2, x3, y3;
	double tmp, ans = 0.0, tmpd;
	int flag = 0;

	x1 = y1 = 0;
	x2 = px(1 / w, 0, -(1 / vr), d / vr);
	y2 = py(1 / w, 0, -(1 / vr), d / vr);

	do {
		tmp = sqrt(pow(x2 - x1, 2) + pow(y2 - y1, 2));
		ans += tmp;

		if (flag) {
			x3 = px(-(1 / vr), d / vr, 1 / w, y2 - 1 / w * x2);
			y3 = py(-(1 / vr), d / vr, 1 / w, y2 - 1 / w * x2);
		}
		else {
			x3 = px(1 / vl, 0, -(1 / w), y2 + 1 / w * x2);
			y3 = py(1 / vl, 0, -(1 / w), y2 + 1 / w * x2);
		}

		x1 = x2; x2 = x3;
		y1 = y2; y2 = y3;
		tmpd = x2 - x1 > 0 ? x2 - x1 : x1 - x2;

		flag = !flag;
	}
	while (tmpd > 10e-8);

	printf("%.7lf\n", ans);
	return 0;
}
0