-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathQueen's Attack II.py
67 lines (60 loc) · 1.4 KB
/
Queen's Attack II.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
67
#!/bin/python
import sys
n, k = raw_input().strip().split(' ')
n, k = [int(n), int(k)]
rQueen, cQueen = raw_input().strip().split(' ')
rQueen, cQueen = [int(rQueen), int(cQueen)]
obstacle = []
attack = 0
for a0 in xrange(k):
obstacle.append(":".join(raw_input().strip().split(' ')))
# Right & Left
xr = xl = cQueen
xdr = xdl = rQueen
fl = fr = fdr = fdl = 0
while(True):
xr += 1
xdr += 1
xdl -= 1
xl -= 1
sr = str(rQueen) + ":" + str(xr)
sl = str(rQueen) + ":" + str(xl)
sdr = str(xdr) + ":" + str(xr)
sdl = str(xdl) + ":" + str(xl)
if xr <= n and sr not in obstacle and fr != 1:
attack += 1
else:
fr = 1
if xl >= 1 and sl not in obstacle and fl != 1:
attack += 1
else:
fl = 1
if xdr <= n and xr <= n and sdr not in obstacle and fdr != 1:
attack += 1
else:
fdr = 1
if xdl >= 1 and xl >= 1 and sdl not in obstacle and fdl != 1:
attack += 1
else:
fdl = 1
if fl == fr == fdl == fdr == 1:
break
# Top & Bottim
yt = yb = rQueen
fb = ft = 0
while(True):
yt += 1
yb -= 1
st = str(yt) + ":" + str(cQueen)
sb = str(yb) + ":" + str(cQueen)
if yt <= n and st not in obstacle and ft != 1:
attack += 1
else:
ft = 1
if yb >= 1 and sb not in obstacle and fb != 1:
attack += 1
else:
fb = 1
if ft == fb == 1:
break
print attack