結果

問題 No.1626 三角形の構築
ユーザー 👑 ygussanyygussany
提出日時 2021-07-23 23:13:22
言語 C
(gcc 12.3.0)
結果
WA  
実行時間 -
コード長 1,330 bytes
コンパイル時間 228 ms
コンパイル使用メモリ 33,920 KB
実行使用メモリ 5,376 KB
最終ジャッジ日時 2024-04-20 16:04:41
合計ジャッジ時間 1,482 ms
ジャッジサーバーID
(参考情報)
judge2 / judge1
このコードへのチャレンジ
(要ログイン)

テストケース

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

ソースコード

diff #

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

const long double eps = 1e-7;

long double area_of_triangle(long long p, long long q, long long r)
{
	if (p + q <= r) return 0.0;
	
	long double s;
	s = (p + q + r) / 2.0;
	return sqrtl(s * (s - p) * (s - q) * (s - r));
}

void solve(long long S, long long T)
{
	int i, j, k = 0;
	long long ans[10000][3], l, r, m;
	for (i = 1; i * i <= S; i++) {
		if (S % i != 0) continue;
		l = i;
		r = (T - i) / 2;
		if (l <= r) {
			while (l < r) {
				m = (l + r) / 2;
				if (S - area_of_triangle(i, m, T - i - m) > eps) l = m + 1;
				else r = m;
			}
			if (fabsl(area_of_triangle(i, l, T - i - l) - S) < eps) {
				ans[k][0] = i;
				ans[k][1] = l;
				ans[k++][2] = T - i - l;
			}
		}
		
		i = S / i;
		l = i;
		r = (T - i) / 2;
		if (l <= r) {
			while (l < r) {
				m = (l + r) / 2;
				if (S - area_of_triangle(i, m, T - i - m) > eps) l = m + 1;
				else r = m;
			}
			if (fabsl(area_of_triangle(i, l, T - i - l) - S) < eps) {
				ans[k][0] = i;
				ans[k][1] = l;
				ans[k++][2] = T - i - l;
			}
		}
		i = S / i;
	}
	printf("%d\n", k);
	for (i = 0; i < k; i++) printf("%lld %lld %lld\n", ans[i][0], ans[i][1], ans[i][2]);
}

int main()
{
	int i, t;
	long long S, T;
	scanf("%d", &t);
	for (i = 1; i <= t; i++) {
		scanf("%lld %lld", &S, &T);
		solve(S, T);
	}
	fflush(stdout);
	return 0;
}
0