結果

問題 No.2602 Real Collider
ユーザー mkawa2
提出日時 2024-07-22 22:31:29
言語 PyPy3
(7.3.15)
結果
AC  
実行時間 1,117 ms / 2,000 ms
コード長 2,852 bytes
コンパイル時間 164 ms
コンパイル使用メモリ 82,032 KB
実行使用メモリ 95,900 KB
最終ジャッジ日時 2024-07-22 22:32:19
合計ジャッジ時間 48,092 ms
ジャッジサーバーID
(参考情報)
judge5 / judge1
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 3
other AC * 78
権限があれば一括ダウンロードができます

ソースコード

diff #

import sys

# sys.setrecursionlimit(200005)
# sys.set_int_max_str_digits(200005)
int1 = lambda x: int(x)-1
pDB = lambda *x: print(*x, end="\n", file=sys.stderr)
p2D = lambda x: print(*x, sep="\n", end="\n\n", file=sys.stderr)
def II(): return int(sys.stdin.readline())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
def SI(): return sys.stdin.readline().rstrip()

dij = [(0, 1), (-1, 0), (0, -1), (1, 0)]
# dij = [(0, 1), (-1, 0), (0, -1), (1, 0), (1, 1), (1, -1), (-1, 1), (-1, -1)]
# inf = -1-(-1 << 31)
inf = -1-(-1 << 62)

# md = 10**9+7
md = 998244353

from math import gcd
from fractions import Fraction

# t=0 2点
# t=1 傾き分子、傾き分母、1点
class Line:
    def __init__(self, x1, y1, x2, y2, t=0):
        a, b, c = y2-y1, x1-x2, x2*y1-x1*y2
        if t == 1: a, b, c = x1*2, -y1*2, y1*y2-x1*x2
        if a < 0: a, b, c = -a, -b, -c
        g = gcd(a, gcd(b, c))
        self.a, self.b, self.c = a//g, b//g, c//g

    def __eq__(self, other):
        return self.a == other.a and self.b == other.b and self.c == other.c

    def online(self, x, y):
        return self.a*x+self.b*y+self.c == 0

    # 交点の座標(分数)
    def crossf(self, other):
        if self == other: return "same", "same"
        if self.a*other.b == self.b*other.a: return "none", "none"
        return Fraction(self.c*other.b - self.b*other.c,self.b*other.a - self.a*other.b) , Fraction(self.c*other.a - self.a*other.c,self.a*other.b - self.b*other.a)

    # 交点の座標(実数)
    def crossr(self, other):
        if self == other: return "same", "same"
        if self.a*other.b == self.b*other.a: return "none", "none"
        return (self.c*other.b - self.b*other.c)/(self.b*other.a - self.a*other.b) , (self.c*other.a - self.a*other.c)/(self.a*other.b - self.b*other.a)

def d2(i,j):
    x,y=abc[i],abc[i+1]
    s,t=abc[j],abc[j+1]
    return (x-s)**2+(y-t)**2

def midpoint(i,j):
    x,y=abc[i],abc[i+1]
    s,t=abc[j],abc[j+1]
    return Fraction(x+s,2),Fraction(y+t,2)

def trend(i,j):
    x,y=abc[i],abc[i+1]
    s,t=abc[j],abc[j+1]
    return y-t,x-s

q=II()
abc=LI()
a=d2(0,2)
b=d2(0,4)
c=d2(2,4)
mx=max(a,b,c)
# print(a,b,c)
if 2*mx>a+b+c:
    if mx==a:[ox,oy],r=midpoint(0,2),Fraction(a,4)
    if mx==b:[ox,oy],r=midpoint(0,4),Fraction(b,4)
    if mx==c:[ox,oy],r=midpoint(2,4),Fraction(c,4)
else:
    n,d=trend(0,2)
    x,y=abc[0]+abc[2],abc[1]+abc[3]
    l1=Line(d,-n,x,y,1)
    n,d=trend(0,4)
    x,y=abc[0]+abc[4],abc[1]+abc[5]
    l2=Line(d,-n,x,y,1)
    ox,oy=l1.crossf(l2)
    r=(ox-abc[0])**2+(oy-abc[1])**2
# print(ox,oy,r)

for _ in range(q):
    x,y=LI()
    print("Yes" if (x-ox)**2+(y-oy)**2<=r else "No")
0