-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueenAttack2.cpp
More file actions
117 lines (110 loc) · 2.85 KB
/
QueenAttack2.cpp
File metadata and controls
117 lines (110 loc) · 2.85 KB
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <unordered_map>
using namespace std;
int main(){
int n;
int k;
cin >> n >> k;
int rQ;
int cQ;
cin >> rQ >> cQ; // coordinates of Queen
int countTotal=0,countR=0,countL=0,countUp=0,countDown=0,countNW=0,countSE=0,countNE=0,countSW=0;
int prevR=0,prevL=0,prevUp=0,prevDown=0,prevNW=0,prevSE=0,prevNE=0,prevSW=0;
countR = n - cQ;
countL = cQ - 1;
countUp = n - rQ;
countDown = rQ - 1;
if(rQ+cQ > n) {
countNW = n - rQ;
countSE = n - cQ;
}
if(rQ + cQ <= n){
countNW = cQ - 1;
countSE = rQ - 1;
}
if(rQ > cQ){
countNE = n - rQ;
countSW = cQ - 1;
}
if(rQ <= cQ){
countNE = n - cQ;
countSW = rQ - 1;
}
for(int a0 = 0; a0 < k; a0++){
int rO;
int cO;
cin >> rO >> cO; // coordinates of obstacle
if(cO > cQ && rO == rQ){ // right
prevR = cO - cQ - 1;
if(prevR < countR){
countR = prevR;
}
}
if(cO < cQ && rO == rQ){ // left
prevL = cQ - cO - 1;
if(prevL < countL){
countL = prevL;
}
}
if(rO > rQ && cO == cQ){ // Up
prevUp = rO - rQ - 1;
if(prevUp < countUp){
countUp = prevUp;
}
}
if(rO < rQ && cO == cQ){ // Down
prevDown = rQ - rO - 1;
if(prevDown < countDown){
countDown = prevDown;
}
}
if(rO > rQ && rO+cO == rQ+cQ){ // NW
prevNW = rO - rQ - 1;
if(prevNW < countNW){
countNW = prevNW;
}
}
if(cO > cQ && rO+cO == rQ+cQ){ // SE
prevSE = cO - cQ - 1;
if(prevSE < countSE){
countSE = prevSE;
}
}
if(rO > rQ && rO-rQ == cO-cQ){ // NE
prevNE = rO - rQ - 1;
if(prevNE < countNE){
countNE = prevNE;
}
}
if(rO < rQ && rO-rQ == cO-cQ){ // SW
prevSW = rQ - rO - 1;
if(prevSW < countSW){
countSW = prevSW;
}
}
}
//cout<<countR<<endl<<countL<<endl<<countUp<<endl<<countDown<<endl<<countNW<<endl<<countSE<<endl<<countNE<<endl<<countSW;
countTotal = countR + countL + countUp + countDown + countNW + countSE + countNE + countSW;
cout<<countTotal;
return 0;
}