Answer to Question #335338 in Python for Venkatesh Reddy

Question #335338

#Hi sir We need Exact answer we believe your Experience


Number of moves:

you are given a nxn square chessboard with one bishop and k number of obstacles placed on it. A bishop can go to different places in a single move. find the total no.of places that are possible for the bishop in a single move. Each square is referenced by a type describing the row, R, and column, C, where the square is located.


explanation: given N=6 K=2


bishop position 5 2


obstacle positions (2 2), (1 5)


the bishop can move in so o/p is 6


I/p:


6 2


5 2


2 2


1 6


O/p:


6


I/p:


6 4


3 3


1 3


3 1


5 1


1 5


O/p:

7

1
Expert's answer
2022-04-29T08:21:12-0400
[n, k] = input().split(' ')
n = int(n)
k = int(k)
board = []
for i in range(n):
    for j in range(n):
        board.append([i+1, j+1])
lst = []
obst = []
bp = input().split(' ')
bp = [int(bp[0]), int(bp[1])]
for i in range(k):
    obst = input().split(' ')
    lst.append([int(obst[0]), int(obst[1])])
count = 0
for shift in [[1, 1], [-1, 1], [1, -1], [-1, -1]]:
    new_pos = [bp[0] + shift[0], bp[1] + shift[1]]
    while new_pos in board and new_pos not in obst:
        count += 1
        new_pos = [new_pos[0] + shift[0], new_pos[1] + shift[1]]
print(count)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS