Solve exo 3

This commit is contained in:
Gabriel Augendre 2019-11-26 20:33:41 +01:00
parent 22dfd7513a
commit 5f0350e3d7
No known key found for this signature in database
GPG key ID: 1E693F4CE4AEE7B4

46
exo3.py
View file

@ -1,5 +1,49 @@
import sys
def assign_cable(cables):
for i, available in enumerate(cables):
if available == 1:
cables[i] = 0
return i + 1
return False
def restore_cable(cables, cable):
cables[cable] = 1
def main():
pass
lines = []
for line in sys.stdin:
lines.append(line.rstrip("\n"))
number_of_cables, number_of_requests = map(int, lines[0].split())
cables = []
requests = []
for _ in range(number_of_cables):
cables.append(1)
for line in lines[1:]:
start, end = map(int, line.split())
requests.append({"start": start, "end": end, "cable": None})
assignations = []
for time in range(2501):
for request in requests:
if time == request["end"]:
restore_cable(cables, request["cable"])
for request in requests:
if time == request["start"]:
cable = assign_cable(cables)
if cable is False:
print("pas possible")
return
else:
request["cable"] = cable
assignations.append(cable)
print(" ".join(map(str, assignations)))
if __name__ == "__main__":