請問一下有人會飆程式網的圓的聯集ID:2504 嗎?? 求教學~~ :)?

已更新項目:

Python

1 個解答

評分
  • 8 個月前
    最佳解答

    # !python3

    #

    def disSq(p0x, p0y, p1x, p1y): return (p0x-p1x)*(p0x-p1x)+(p0y-p1y)*(p0y-p1y)

    #

    def isInCircle(p0x,p0y,p1x,p1y,dist): return disSq(p0x,p0y,p1x,p1y) <= (dist*dist)

    #

    S = 31

    cnt = int(input())

    cir = []

    for i in range(cnt): cir.append([int(x)*S for x in input().split()])

    x0 = min([x[0]-x[2] for x in cir])

    x1 = max([x[0]+x[2] for x in cir])

    y0 = min([x[1]-x[2] for x in cir])

    y1 = max([x[1]+x[2] for x in cir])

    are = 0

    for x in range(x0, x1+1):

      for y in range(y0,y1+1):

        for j in range(cnt):

          if isInCircle(x,y,cir[j][0],cir[j][1],cir[j][2]):

            are += 1

            break

    #

    print('{}'.format(int(are//(S*S))))

還有問題?馬上發問,尋求解答。