-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRut.py
66 lines (65 loc) · 2.03 KB
/
Rut.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
num = int(input())
hcows = []
vcows = []
cows = []
for n in range(num):
cow = input().split(" ")
cow.append(None)
cow.append(None)
if cow[0] == "N":
cow[3]=cow[1]
vcows.append(cow)
if cow[0] == "E":
cow[4]=cow[2]
hcows.append(cow)
cows.append(cow)
answers = [None]*num
index1 = 0
index2 = 0
for cow in cows:
if cow[0] == "N":
diff = []
for cow2 in hcows:
if int(cow[1]) < int(cow2[1]):
continue
if int(cow[2]) > int(cow2[2]):
continue
if(cow2[3]!=None):
if(int(cow2[3])<int(cow[1])):
continue
if int(cow2[2])-int(cow[2])>int(cow[1])-int(cow2[1]):
diff.append(int(cow2[2])-int(cow[2]))
if int(cow2[2])-int(cow[2])<int(cow[1])-int(cow2[1]):
if cow2[3]!=None:
if int(cow2[3])>int(cow[1]):
cow2[3]=cow[1]
else:
cow2[3] = cow[1]
if(diff==[]):
print("Infinity")
else:
print(min(diff))
cow[4]=int(cow[2])+min(diff)
if cow[0] == "E":
diff = []
for cow2 in vcows:
if int(cow[1]) > int(cow2[1]):
continue
if int(cow[2]) < int(cow2[2]):
continue
if (cow2[4]!=None):
if (int(cow2[4]) < int(cow[2])):
continue
if int(cow2[1]) - int(cow[1]) > int(cow[2]) - int(cow2[2]):
diff.append(int(cow2[1]) - int(cow[1]))
if int(cow2[1]) - int(cow[1]) < int(cow[2]) - int(cow2[2]):
if cow2[4]!=None:
if int(cow2[4])>int(cow[2]):
cow2[4]=int(cow[2])
else:
cow2[4] = int(cow[2])
if (diff == []):
print("Infinity"
else:
print(min(diff))
cow[3]=int(cow[1])+min(diff)