Rezultati

Up. imeNalogaJezikRezultatČas oddaje
rektifikatorji-2018 Fruit Ninja Python 3 100/100OK 13. okt '18 @ 15:20

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 8,527 MiB 0,000 s OK
#2 11/11 8,684 MiB 0,000 s OK
#3 11/11 8,586 MiB 0,000 s OK
#4 11/11 8,723 MiB 0,000 s OK
#5 11/11 8,770 MiB 0,000 s OK
#6 11/11 8,805 MiB 0,000 s OK
#7 11/11 8,715 MiB 0,000 s OK
#8 11/11 8,820 MiB 0,000 s OK
#9 12/12 8,723 MiB 0,000 s OK

Ocenjevani program (ninja.py):
import sys
import math

l = input().split(" ")
line = [
    [float(l[0]), float(l[1])],
    [float(l[2]), float(l[3])]
]

lx = sorted(line, key=lambda i: i[0])
ly = sorted(line, key=lambda i: i[1])

# edge case 0
if (lx[0][0] == lx[1][0] and lx[0][1] == lx[1][1]):
    print(0)
    exit(0)

N = int(input())

circles = []

i = 0
while i < N:
    line = input().split(" ")
    Xi = float(line[0])
    Yi = float(line[1])
    Ri = float(line[2])
    circles.append([Xi, Yi, Ri])
    i += 1

def distance(x1,y1, x2,y2):
    return math.sqrt( math.pow(x2-x1,2.0) + math.pow(y2-y1,2.0) )

def presecisce(circle):
    x0 = circle[0]
    y0 = circle[1]
    r = circle[2]

    Xa = lx[0][0]
    Ya = lx[0][1]
    Xb = lx[1][0]
    Yb = lx[1][1]

    if distance(Xa,Ya, x0,y0) <= r and distance(Xb,Yb, x0,y0) <= r:
        return True
    elif Xa == Xb:
        Xa = ly[0][0]
        Ya = ly[0][1]
        Xb = ly[1][0]
        Yb = ly[1][1]

        D = 4.0 * (-math.pow(Xa-x0, 2.0) + r*r)
        if D < 0.0: return False

        y1 = y0 - math.sqrt(r * r - math.pow(Xa - x0, 2.0))
        y2 = y0 + math.sqrt(r * r - math.pow(Xa - x0, 2.0))
        ps = [y1, y2]

        for p in ps:
            if Yb >= p and Ya <= p:
                return True
    else:
        k = (Yb-Ya) / (Xb-Xa)
        n = Ya - k*Xa
        a = k*k+1.0
        b = 2.0*(k*n-k*y0-x0)
        c = n*n + y0*y0 + x0*x0 - r*r - 2.0*n*y0

        D = b*b - 4.0*a*c
        if D < 0: return False

        x1 = (-b - math.sqrt(D)) / (2.0*a)
        x2 = (-b + math.sqrt(D)) / (2.0 * a)
        y1 = k*x1+n
        y2 = k*x2+n

        p = [[x1,y1], [x2,y2]]
        if p is None: return False
        for x in p:
            if Xa <= x[0] and Xb >= x[0]:
                return True

    return False

def slices(p):
    if p is None: return False

    for x in p:
        if Xa <= x[0] and Xb >= x[0]:
            return True

    return False

S = 0
i = 0
while i < N:
    p = presecisce(circles[i])
    if p: S += 1
    i += 1

print(S)