結果

問題 No.105 arcの六角ボルト
ユーザー lam6er
提出日時 2025-03-20 18:53:16
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 160 ms / 5,000 ms
コード長 1,862 bytes
コンパイル時間 328 ms
コンパイル使用メモリ 82,448 KB
実行使用メモリ 80,328 KB
最終ジャッジ日時 2025-03-20 18:54:25
合計ジャッジ時間 1,220 ms
ジャッジサーバーID
(参考情報)
judge2 / judge3
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
other AC * 1
権限があれば一括ダウンロードができます

ソースコード

diff #

import math
import sys

def main():
    input_lines = [line.strip() for line in sys.stdin if line.strip()]
    ptr = 0
    T = int(input_lines[ptr])
    ptr += 1
    for _ in range(T):
        # Skip empty lines between test cases
        while ptr < len(input_lines) and input_lines[ptr] == '':
            ptr += 1
        points = []
        for _ in range(6):
            if ptr >= len(input_lines):
                break
            x, y = map(float, input_lines[ptr].split())
            ptr += 1
            points.append((x, y))
        candidates = []
        for x, y in points:
            theta_rad = math.atan2(y, x)
            theta_deg = math.degrees(theta_rad) % 360.0
            for alpha in [0.0, 60.0, 120.0, 180.0, 240.0, 300.0]:
                candidate = (theta_deg - alpha) % 360.0
                if 0.0 <= candidate < 50.0:
                    candidates.append(candidate)
        # Sort the candidates to find the best cluster
        candidates.sort()
        max_cluster = []
        eps = 1e-8  # Adjusted to handle floating-point precision
        n = len(candidates)
        i = 0
        while i < n:
            current_val = candidates[i]
            j = i + 1
            while j < n and (candidates[j] - current_val) <= eps:
                j += 1
            current_cluster = candidates[i:j]
            if len(current_cluster) > len(max_cluster):
                max_cluster = current_cluster
            i = j
        # Calculate the average of the best cluster
        if not max_cluster:
            # According to the problem statement, this case should not occur
            print("0.0000000000")
        else:
            avg_theta = sum(max_cluster) / len(max_cluster)
            # Print with sufficient precision
            print("{0:.10f}".format(avg_theta))
            
if __name__ == "__main__":
    main()
0