-
-
Save ParrotParrot/7b023d04227c44c7651da5347e5c9960 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/python3 | |
import math | |
import os | |
import random | |
import re | |
import sys | |
# Complete the queensAttack function below. | |
def queensAttack(n, k, r_q, c_q, obstacles): | |
if n < 2: return 0 | |
if k == 0: | |
dx = min(c_q-1, n-c_q) | |
dy = min(r_q-1, n-r_q) | |
return((3*(n-1))+(min(dx,dy)*2)) | |
counter = 0 | |
HObstacles = [item[1] for item in obstacles if item[0] == r_q] | |
VObstacles = [item[0] for item in obstacles if item[1] == c_q] | |
leftbound = [item for item in HObstacles if item < c_q] | |
if leftbound: leftbound = max(leftbound) | |
else: leftbound = 0 | |
rightbound = [item for item in HObstacles if item > c_q] | |
if rightbound: rightbound = min(rightbound) | |
else: rightbound = n+1 | |
bottombound = [item for item in VObstacles if item < r_q] | |
if bottombound: bottombound = max(bottombound) | |
else: bottombound = 0 | |
topbound = [item for item in VObstacles if item > r_q] | |
if topbound: topbound = min(topbound) | |
else: topbound = n+1 | |
counter += (rightbound-leftbound) + (topbound-bottombound) - 4 | |
RminC = r_q - c_q | |
SWEObstacles = [item for item in obstacles if item[0]-item[1] == RminC] | |
RsumC = r_q + c_q | |
NWEObstacles = [item for item in obstacles if item[0]+item[1] == RsumC] | |
blbound = [item[1] for item in SWEObstacles if item[1] < c_q] | |
if blbound: blbound = max(blbound) | |
else: blbound = abs(max(0,RminC)) | |
brbound = [item[1] for item in NWEObstacles if item[1] > c_q] | |
if brbound: brbound = min(brbound) | |
else: brbound = abs(min(n+1,RsumC)) | |
tlbound = [item[1] for item in NWEObstacles if item[1] < c_q] | |
if tlbound: tlbound = max(tlbound) | |
else: tlbound = abs(min(0,n-RsumC+1)) | |
trbound = [item[1] for item in SWEObstacles if item[1] > c_q] | |
if trbound: trbound = min(trbound) | |
else: trbound = abs(min(n+1,(((n-r_q)+RsumC)+((n-c_q)+RsumC)+3))) | |
counter += (trbound-blbound) + (brbound-tlbound) - 4 | |
print("nigger", counter) | |
return(counter) | |
if __name__ == '__main__': | |
#fptr = open("Z:\output.txt", 'w') | |
magic = open("Z:\input2.txt", 'r') | |
nk = magic.readline().split() | |
n = int(nk[0]) | |
k = int(nk[1]) | |
r_qC_q = magic.readline().split() | |
r_q = int(r_qC_q[0]) | |
c_q = int(r_qC_q[1]) | |
obstacles = [] | |
for _ in range(k): | |
obstacles.append(list(map(int, magic.readline().rstrip().split()))) | |
result = queensAttack(n, k, r_q, c_q, obstacles) | |
#fptr.write(str(result) + '\n') | |
#fptr.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment