Rezultati

Up. imeNalogaJezikRezultatČas oddaje
zerodays-2018 Fruit Ninja Python 3 100/100OK 13. okt '18 @ 11:41

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 8,664 MiB 0,000 s OK
#2 11/11 8,594 MiB 0,000 s OK
#3 11/11 8,613 MiB 0,000 s OK
#4 11/11 8,691 MiB 0,000 s OK
#5 11/11 8,605 MiB 0,000 s OK
#6 11/11 8,551 MiB 0,000 s OK
#7 11/11 8,609 MiB 0,000 s OK
#8 11/11 8,672 MiB 0,000 s OK
#9 12/12 8,680 MiB 0,000 s OK

Ocenjevani program (fruit_ninja.py):
import math

x_a, y_a, x_b, y_b = map(int, input().split())

def prod(a, b):
    a_1, a_2 = a
    b_1, b_2 = b

    return abs(
        a_1 * b_2 - a_2 * b_1
    )

n = int(input())

izrojeno = False

if x_a == x_b and y_a == y_b:
    izrojeno = True
else:
    e = (x_b - x_a, y_b - y_a)

    l = math.sqrt(e[0] ** 2 + e[1] ** 2)

    e = (e[0] / l, e[1] / l)

c = 0

for i in range(n):
    x, y, r = map(int, input().split())

    if izrojeno:
        d_a = (x - x_a) ** 2 + (y - y_a) ** 2

        if d_a <= r ** 2:
            c += 1
          
        continue


    t = (x - x_a, y - y_a)

    razdalja = prod(e, t)

    if razdalja <= r:
        # projeciramo tocko na premico

        lambd = e[0] * t[0] + e[1] * t[1]
        projekcija = (x_a + e[0] * lambd, y_a + e[1] * lambd)

        x1, x2 = sorted((x_a, x_b))
        y1, y2 = sorted((y_a, y_b))

        if x1 <= projekcija[0] and projekcija[0] <= x2 and y1 <= projekcija[1] and projekcija[1] <= y2:
            c += 1
        else:
            d_a = (x - x_a) ** 2 + (y - y_a) ** 2

            if d_a <= r ** 2:
                c += 1
            else:
                d_b = (x - x_b) ** 2 + (y - y_b) ** 2

                if d_b <= r ** 2:
                    c += 1


print(c)