Rezultati

Up. imeNalogaJezikRezultatČas oddaje
ognjeniprocesor-2018 Presek Python 3 100/100OK 04. okt '18 @ 20:05

Test Točke Porabljen spomin Porabljen čas Status
#1 100/100 8,738 MiB 0,000 s OK

Ocenjevani program (Presek.py):
from math import sqrt


def pt_in_rectangle(pt, rect):
    return rect[0][0] <= pt[0] <= rect[1][0] and rect[0][1] <= pt[1] <= rect[1][1]


def pt_in_circle(pt, xk, yk, r):
    x, y = pt
    return (x-xk)**2. + (y-yk)**2. <= r**2.


def preveri_rob(y, xk, yk, r):
    try:
        x1 = sqrt(r**2 - (y-yk)**2) + xk
        x2 = -sqrt(r**2 - (y-yk)**2) + xk
        return x1, x2
    except:
        pass

T = int(input().strip())
for i in range(T):
    line = input().split()
    line = [int(x) for x in line]
    rect = [(line[0], line[1]), (line[2], line[3])]
    xk, yk = line[4], line[5]
    r = line[6]
    found = False
    if pt_in_rectangle((xk, yk), rect):
        if xk == int(xk): xk = int(xk)
        if yk == int(yk): yk = int(yk)
        print(xk, yk)
        found = True
    if found: continue
    for pt in [(rect[0][0], rect[0][1]), (rect[1][0], rect[1][1]), (rect[0][0], rect[1][1]), (rect[1][0], rect[0][1])]:
        if pt_in_circle(pt, xk, yk, r):
            tx, ty = pt
            if tx == int(tx): tx = int(tx)
            if ty == int(ty): ty = int(ty)
            print(tx, ty)
            found = True
            break
    if found: continue

    for i in range(2):
        pts = []
        y = preveri_rob(rect[i][0], yk, xk, r)
        # if y: pts += list(zip([rect[i][0]] * 2, y))
        if y: pts += [(rect[i][0], sum(y)/2.)]
        x = preveri_rob(rect[i][1], xk, yk, r)
        # if x: pts += list(zip(x, [rect[i][1]] * 2))
        if x: pts += [(sum(x)/2., rect[i][1])]
        found = False
        for pt in pts:
            if pt_in_rectangle(pt, rect):
                tx, ty = pt
                if tx == int(tx): tx = int(tx)
                if ty == int(ty): ty = int(ty)
                print(tx, ty)
                found = True
                break
        if found: break
    if not found:
        print("Presek je prazen")