-
Notifications
You must be signed in to change notification settings - Fork 0
/
Queen's Attack II
84 lines (69 loc) · 2.1 KB
/
Queen's Attack II
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import math
import os
import random
import re
import sys
#
# Complete the 'queensAttack' function below.
#
# The function is expected to return an INTEGER.
# The function accepts following parameters:
# 1. INTEGER n
# 2. INTEGER k
# 3. INTEGER r_q
# 4. INTEGER c_q
# 5. 2D_INTEGER_ARRAY obstacles
#
def queensAttack(n, k, r_q, c_q, obstacles):
# Write your code here
lo = [[c_q-1, n-c_q], [r_q-1, n-r_q], [min(r_q, c_q)-1, n-max(r_q, c_q)], [min(r_q-1, n-c_q), min(n-r_q, c_q-1)]]
for i in obstacles:
print(lo)
print(i)
if i[0] == r_q:
t = i[1] - c_q
if t < 0:
if -t - 1 < lo[0][0]:
lo[0][0] = -t - 1
else:
if t - 1 < lo[0][1]:
lo[0][1] = t - 1
elif i[1] == c_q:
t = i[0] - r_q
if t < 0:
if -t - 1 < lo[1][0]:
lo[1][0] = -t - 1
else:
if t - 1 < lo[1][1]:
lo[1][1] = t - 1
elif i[0] - i[1] == r_q - c_q:
t = i[0] - r_q
if t < 0:
if -t - 1 < lo[2][0]:
lo[2][0] = -t - 1
else:
if t - 1 < lo[2][1]:
lo[2][1] = t - 1
elif i[0] + i[1] == r_q + c_q:
t = c_q - i[1]
if t < 0:
if -t - 1 < lo[3][0]:
lo[3][0] = -t - 1
else:
if t - 1 < lo[3][1]:
lo[3][1] = t - 1
return sum([sum(i) for i in lo])
if __name__ == '__main__':
fptr = open(os.environ['OUTPUT_PATH'], 'w')
first_multiple_input = input().rstrip().split()
n = int(first_multiple_input[0])
k = int(first_multiple_input[1])
second_multiple_input = input().rstrip().split()
r_q = int(second_multiple_input[0])
c_q = int(second_multiple_input[1])
obstacles = []
for _ in range(k):
obstacles.append(list(map(int, input().rstrip().split())))
result = queensAttack(n, k, r_q, c_q, obstacles)
fptr.write(str(result) + '\n')
fptr.close()