from collections import defaultdict
class Pair:
def init(self, first, second):
self.first = first
self.second = second
def eq(self, other):
return self.first == other.first and self.second == other.second
def hash(self):
return hash((self.first, self.second))
def main():
num_wires = int(input())
paths = []
point_to_segments_map = defaultdict(list)
for _ in range(num_wires):
x1, y1, x2, y2 = map(int, input().split())
delta_x = x2 - x1
delta_y = y2 - y1
steps = max(abs(delta_x), abs(delta_y))
step_x = 0 if delta_x == 0 else delta_x // abs(delta_x)
step_y = 0 if delta_y == 0 else delta_y // abs(delta_y)
path = []
for step in range(steps + 1):
current_x = x1 + step_x * step
current_y = y1 + step_y * step
path.append(Pair(current_x, current_y))
point_to_segments_map[Pair(current_x, current_y)].append(len(paths))
paths.append(path)
animal_resistances = {}
animal_info = input().split()
for info in animal_info:
animal, resistance = info.split(":")
animal_resistances[animal] = int(resistance)
touched_animal = input()
total_voltage = 0
for point, segments in point_to_segments_map.items():
if len(segments) >= 2:
overlap_count = len(segments)
min_cost = float("inf")
for segment_id in segments:
segment_path = paths[segment_id]
index = segment_path.index(point)
left_moves = index
right_moves = len(segment_path) - index - 1
move_cost = min(left_moves, right_moves) if left_moves > 0 and right_moves > 0 else max(left_moves, right_moves)
min_cost = min(min_cost, move_cost)
total_voltage += overlap_count * min_cost
if touched_animal in animal_resistances:
if total_voltage >= animal_resistances[touched_animal]:
print("Yes")
else:
print("No")
else:
print("No")
valid_animal_count = sum(1 for resistance in animal_resistances.values() if total_voltage >= resistance)
success_rate = valid_animal_count / len(animal_resistances)
print("{:.2f}".format(success_rate))
if name == "main":
main()
Fence voltage - CodeVita ✅30 Noy 2024, 03:38

