結果
問題 | No.2632 Center of Three Points in Lp Norm |
ユーザー | tatyam |
提出日時 | 2024-02-16 22:37:36 |
言語 | Python3 (3.12.2 + numpy 1.26.4 + scipy 1.12.0) |
結果 |
AC
|
実行時間 | 598 ms / 2,000 ms |
コード長 | 1,544 bytes |
コンパイル時間 | 122 ms |
コンパイル使用メモリ | 13,056 KB |
実行使用メモリ | 44,728 KB |
最終ジャッジ日時 | 2024-09-28 21:13:23 |
合計ジャッジ時間 | 26,763 ms |
ジャッジサーバーID (参考情報) |
judge2 / judge1 |
(要ログイン)
テストケース
テストケース表示入力 | 結果 | 実行時間 実行使用メモリ |
---|---|---|
testcase_00 | AC | 579 ms
44,204 KB |
testcase_01 | AC | 577 ms
44,212 KB |
testcase_02 | AC | 588 ms
44,456 KB |
testcase_03 | AC | 572 ms
44,460 KB |
testcase_04 | AC | 585 ms
44,208 KB |
testcase_05 | AC | 574 ms
44,472 KB |
testcase_06 | AC | 580 ms
44,728 KB |
testcase_07 | AC | 569 ms
44,212 KB |
testcase_08 | AC | 560 ms
44,208 KB |
testcase_09 | AC | 574 ms
44,680 KB |
testcase_10 | AC | 591 ms
44,464 KB |
testcase_11 | AC | 585 ms
44,336 KB |
testcase_12 | AC | 589 ms
44,204 KB |
testcase_13 | AC | 584 ms
44,472 KB |
testcase_14 | AC | 589 ms
44,464 KB |
testcase_15 | AC | 591 ms
44,720 KB |
testcase_16 | AC | 589 ms
44,208 KB |
testcase_17 | AC | 587 ms
44,212 KB |
testcase_18 | AC | 587 ms
44,336 KB |
testcase_19 | AC | 593 ms
44,208 KB |
testcase_20 | AC | 590 ms
44,468 KB |
testcase_21 | AC | 574 ms
44,208 KB |
testcase_22 | AC | 572 ms
44,204 KB |
testcase_23 | AC | 568 ms
44,088 KB |
testcase_24 | AC | 563 ms
44,464 KB |
testcase_25 | AC | 568 ms
44,460 KB |
testcase_26 | AC | 567 ms
44,208 KB |
testcase_27 | AC | 565 ms
44,340 KB |
testcase_28 | AC | 577 ms
44,208 KB |
testcase_29 | AC | 581 ms
44,336 KB |
testcase_30 | AC | 596 ms
44,208 KB |
testcase_31 | AC | 598 ms
44,468 KB |
testcase_32 | AC | 579 ms
44,204 KB |
testcase_33 | AC | 577 ms
44,464 KB |
testcase_34 | AC | 581 ms
44,460 KB |
testcase_35 | AC | 578 ms
44,472 KB |
testcase_36 | AC | 579 ms
44,592 KB |
testcase_37 | AC | 585 ms
44,084 KB |
ソースコード
import numpy as np from math import pi, cos, sin, atan2 import sys ZERO = np.array([0.0, 0.0]) get = lambda: np.array(list(map(float, input().split()))) def norm(a) -> float: x = abs(a[0]) y = abs(a[1]) return (x ** p + y ** p) ** (1 / p) def dist(a, b): return norm(a - b) def cross(a, b): return a[0] * b[1] - a[1] * b[0] p = float(input()) a = get() b = get() c = get() if a[0] > b[0]: a, b = b, a if a[0] > c[0]: a, c = c, a if cross(b - a, c - a) < 0: b, c = c, b A = a.copy() a -= A b -= A c -= A B = -pi C = pi def atan(diff) -> float: return atan2(diff[1], diff[0]) def near(diff) -> int: da = dist(a, diff) db = dist(b, diff) dc = dist(c, diff) mn = min(da, db, dc) if da == mn: return 0 if db == mn: return 1 return 2 def bisect_a(di): ok = 1e7 ng = 0.0 for _ in range(100): mid = (ok + ng) / 2 if near(di * mid) == 0: ng = mid else: ok = mid return di * ok def direction(theta): return np.array([cos(theta), sin(theta)]) def check(theta): di = direction(theta) x = bisect_a(di) n = near(x) if n: return n if theta < atan(b): return 1 return 2 for _ in range(100): theta = (B + C) / 2 if check(theta) == 1: B = theta else: C = theta ans = bisect_a(direction(B)) if max(abs(ans[0]), abs(ans[1])) > 1e6: ans = bisect_a(direction(C)) print(dist(a, ans), dist(b, ans), dist(c, ans), file=sys.stderr) print(*(ans + A))