-
-
Notifications
You must be signed in to change notification settings - Fork 110
/
Copy pathQueen'sAttackII.java
67 lines (65 loc) · 1.82 KB
/
Queen'sAttackII.java
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
import java.io.*;
import java.util.*;
import java.text.*;
import java.math.*;
import java.util.regex.*;
public class Solution {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
int n = in.nextInt();
int k = in.nextInt();
int rq = in.nextInt();
int cq = in.nextInt();
int e=n-cq, north=n-rq, w=cq-1, s=rq-1;
int ne=Math.min(north,e), se = Math.min(s,e), nw = Math.min(north,w), sw = Math.min(s,w);
for(int a0 = 0; a0 < k; a0++){
int ro = in.nextInt();
int co = in.nextInt();
int r = ro-rq;
int c = co-cq;
if(r==0) {
if(c>0){
if(c-1<e){
e = c-1;
}
} else {
if(-c-1<w){
w = -c-1;
}
}
} else if(c==0) {
if(r>0) {
if(r-1<north){
north = r-1;
}
} else {
if(-r-1<s){
s = -r-1;
}
}
} else if(r==c) {
if(r>0){
if(r-1<ne){
ne = r-1;
}
} else {
if(-r-1<sw){
sw = -r-1;
}
}
} else if(r==-c) {
if(r>0){
if(r-1<nw){
nw = r-1;
}
} else {
if(-r-1<se){
se = -r-1;
}
}
}
}
int count = e+ne+north+nw+w+s+se+sw;
System.out.println(count);
}
}