Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Vector:
- def __init__(self, x, y):
- self.x = x
- self.y = y
- def lenv(a, b):
- return ((a.x - b.x) ** 2 + (a.y - b.y) ** 2) ** 0.5
- n, l, k = map(int, input().split())
- if k:
- holes = list(map(lambda x: int(x) - 1, input().split()))
- else:
- holes = []
- fence = []
- for i in range(n):
- x, y = map(int, input().split())
- fence.append(Vector(x, y))
- fromz = 0
- pos = 0
- l1 = 0
- hl = [0]
- ans = 0
- for i in range(n):
- if i == holes[pos] and not pos:
- fromz = l1
- l1 = 0
- pos += 1
- pos %= k
- elif i == holes[pos]:
- hl.append(l1)
- l1 = 0
- pos += 1
- pos %= k
- else:
- l1 += lenv(fence[i], fence[(i + 1) % n])
- i += 1
- i %= n
- hl[0] = l1 + fromz
- s = 0
- for hole_ind in range(k):
- s += lenv(fence[holes[hole_ind]], fence[(holes[hole_ind] + 1) % n])
- nowl = l
- ansn = 0
- ind = hole_ind
- flag = False
- while nowl > 0 and not (flag and ind == hole_ind):
- pos = holes[ind]
- tmp = lenv(fence[pos], fence[(pos + 1) % n])
- if tmp <= nowl:
- ansn += tmp
- nowl -= tmp
- else:
- ansn += nowl
- nowl = 0
- nowl -= hl[ind]
- ind = (ind + 1) % k
- ans = max(ansn, ans)
- print(s - ans)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement