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 __neg__(self):
- return Vector(-self.x, -self.y)
- def __add__(self, other):
- return Vector(self.x + other.x, self.y + other.y)
- def __sub__(self, other):
- return Vector(self.x - other.x, self.y - other.y)
- def __mul__(self, k):
- return Vector(k * self.x, k * self.y)
- def __rmul__(self, k):
- return Vector(k * self.x, k * self.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 > 0:
- holes = set(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))
- ansM = 0
- s = 0
- for num in holes:
- nowl = l
- ansNow = 0
- pos = num
- flag = False
- s += lenv(fence[num], fence[(num + 1) % n])
- while nowl > 0 and not (flag and pos == num):
- if pos in holes:
- tmp = lenv(fence[pos], fence[(pos + 1) % n])
- if tmp <= nowl:
- ansNow += tmp
- nowl -= tmp
- else:
- ansNow += nowl
- nowl = 0
- else:
- nowl -= lenv(fence[pos], fence[(pos + 1) % n])
- pos += 1
- pos %= n
- flag = True
- #print(num, ansNow)
- ansM = max(ansM, ansNow)
- nowl = l
- ansNow = 0
- pos = num
- flag = False
- while nowl > 0 and not (flag and pos == num):
- if pos in holes:
- tmp = lenv(fence[pos], fence[(pos - 1) % n])
- if tmp <= nowl:
- ansNow += tmp
- nowl -= tmp
- else:
- ansNow += nowl
- nowl = 0
- else:
- nowl -= lenv(fence[pos], fence[(pos - 1) % n])
- pos -= 1
- pos %= n
- flag = True
- #print(num, ansNow)
- ansM = max(ansM, ansNow)
- print('{:.6f}'.format(s - ansM))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement