Rezultati

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

Test Točke Porabljen spomin Porabljen čas Status
#1 11/11 8,676 MiB 0,000 s OK
#2 11/11 8,664 MiB 0,000 s OK
#3 11/11 8,680 MiB 0,000 s OK
#4 11/11 8,656 MiB 0,000 s OK
#5 11/11 8,664 MiB 0,000 s OK
#6 11/11 8,672 MiB 0,000 s OK
#7 11/11 8,578 MiB 0,000 s OK
#8 11/11 8,668 MiB 0,000 s OK
#9 12/12 8,648 MiB 0,000 s OK

Ocenjevani program (3.py):
import sys

#sys.stdin = open("3.in")

xa, ya, xb, yb = map(int, sys.stdin.readline().split())
n = int(sys.stdin.readline().strip())


vodoravna = False

if xa == xb:
    navpicna = True
    k = None
    np = None
    if ya == yb:
        vodoravna = True
else:
    navpicna = False
    if ya == yb:
        vodoravna = True
    k = (yb - ya) / (xb - xa)
    np = ya - k * xa

def f(k, n, x):
    return k*x + n

def f_inv(k, n, y):
    return (y - n)/k

def seka_navpicna(pi, qi, ri, xa, ya, yb):
    if (xa - pi)**2 + (ya - qi)**2 <= ri**2 or (xa - pi)**2 + (yb - qi)**2 <= ri**2:
        return True
    elif (ya > qi+ri and yb > qi+ri) or (ya < qi-ri and yb < qi-ri):
        return False
    elif abs(xa-pi) <= ri and ((ya>qi and yb<qi)  or (ya<qi and yb>qi)) :
        return True
    else:
        return False

def seka_vodoravna(pi, qi, ri, xa, xb, yb):
    if (xa - pi)**2 + (yb - qi)**2 <= ri**2 or (xb - pi)**2 + (yb - qi)**2 <= ri**2:
        return True
    elif (xa > pi+ri and xb > pi+ri) or (xa < pi-ri and xb< pi-ri):
        return False
    elif abs(yb-qi) <= ri and ((xa>pi and xb<pi) or (xa<pi and xb>pi)):
        return True
    else:
        return False

def seka(pi, qi, ri, xa, ya, xb, yb, k, n, navpicna, vodoravna):

    if navpicna:
        if vodoravna:
            return (pi - xa)**2 + (qi - ya)**2 <= ri**2
        return seka_navpicna(pi, qi, ri, xa, ya, yb)

    elif vodoravna:
        return seka_vodoravna(pi, qi, ri, xa, xb, ya)

    else:

        kx_min, kx_max, ky_min, ky_max = pi - ri, pi + ri, qi - ri, qi + ri


        if (xa - pi)**2 + (ya - qi)**2 <= ri**2 or (xb - pi)**2 + (yb - qi)**2 <= ri**2:
             return True

        elif ((xa >= kx_max and xb >= kx_max) or (xa <= kx_min and xb <= kx_min)) or ((ya >= ky_max and yb >= ky_max) or (ya <= ky_min and yb <= ky_min)):
            return False


        kp = -1/k
        np = qi -kp*pi

        x_p = (n - np)/(kp - k)
        y_p = kp*x_p + np

        if (x_p < xa and x_p < xb) or (x_p > xa and x_p > xb):
            return False


        if (pi - x_p)**2 + (qi - y_p)**2 <= ri**2:
            return True

        return False

vsota = 0

for i in range(n):
    pi, qi, ri = map(int, sys.stdin.readline().split())
    rez = seka(pi, qi, ri, xa, ya, xb, yb, k, np, navpicna, vodoravna)
   # print(pi, qi, ri, rez)
    vsota += int(rez)

print(vsota)