結果

問題 No.1624 三角形の反射
ユーザー bal4ubal4u
提出日時 2021-08-11 18:32:56
言語 C
(gcc 12.3.0)
結果
AC  
実行時間 27 ms / 2,000 ms
コード長 989 bytes
コンパイル時間 630 ms
コンパイル使用メモリ 30,060 KB
実行使用メモリ 4,380 KB
最終ジャッジ日時 2023-09-15 04:51:48
合計ジャッジ時間 1,320 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

// yuki 1624 三角形の反射
// 2021.8.11

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

const double eps = 1e-6;
#define EQ(a,b) (fabs((a)-(b)) <= eps)
#define EQZ(a) ((fabs(a)) <= eps)
int aw, ap;

void calc(double px, double py, double fx, double fy) {
	double a, t, x, y;
	while (1) {
		if (EQZ(px) && EQZ(py))   { ap = 'A'; break; }
		if (EQ(px, 1) && EQZ(py)) { ap = 'B'; break; }
		if (EQZ(px) && EQ(py, 1)) { ap = 'C'; break; }
		++aw;

		a = (fy-py)/(fx-px);
		x = px - py/a, y = py - px*a;
		if (!EQZ(px) && y >= 0 && y <= 1.0) {        // x == 0
			px = 0, py = y, fx = -fx;
		} else if (!EQZ(py) && x >= 0 && x <= 1.0) { // y == 0
			px = x, py = 0, fy = -fy;
		} else {                                     // y == -x+1
			x = (1+a*px-py)/(1+a), y = (py+a*(1-px))/(1+a);
			px = x, py = y;
			t = fx; fx = 1-fy, fy = 1-t;
		}
	}
}

int main() {
	double a;
	scanf("%lf", &a);
	calc(1.0/(1+a), a/(1+a), 1.0, 1.0);
	if (aw < 0) puts("-1");
	else printf("%c %d\n", ap, aw);
	return 0;
}
0