We use cookies to ensure you have the best browsing experience on our website. Please read our cookie policy for more information about how we use cookies.
Queen's Attack II
Queen's Attack II
Sort by
recency
|
1014 Discussions
|
Please Login in order to post a comment
I'm failing in a case that maybe I didn't consider. I want to see the discussion to see if someone else had a similar issue or to have ideas of the possible scenarios, instead, I'm getting the Détente Musculaire result. Please avoid pasting here your code. We don't need it, nobody need it!
Here's my solution in TypeScript:
(Notice that the arguments for the queen's position are wrong in the original function.)
import java.util.*; import java.awt.Point;
//thank me later public class Solution { public static void main(String[] args){ Scanner in = new Scanner(System.in);
}
Cries in no. 1 grid problem hater:
step 1: calculate the maximum attacks in eight directions; step 2: if there is obstacle in any one of the eight direction, which one smaller is the distance. def queensAttack(n, k, r_q, c_q, obstacles): # Write your code here dir_dis = {(0,1):n-c_q, (0,-1):c_q - 1, (1, 0): n-r_q, (-1, 0): r_q - 1, (-1, -1):min(r_q - 1, c_q - 1), (1, 1):min(n-r_q, n-c_q), (1, -1): min(n-r_q, c_q-1), (-1, 1):min(r_q-1, n-c_q) } for ro, co in obstacles: dx = ro - r_q dy = co - c_q if dx == 0 or dy == 0 or abs(dx) == abs(dy): dis = abs(dx) if abs(dx) == abs(dy) else max(abs(dx), abs(dy)) di = (dx/dis, dy/dis) dir_dis[di] = min(dir_dis[di], dis - 1) return sum(dir_dis.values())