forked from 7harshit20/dsa
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queens.cpp
62 lines (59 loc) · 1.38 KB
/
queens.cpp
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
#include<iostream>
#include<vector>
using namespace std;
vector<vector<int>> queensAttacktheKing(vector<vector<int>>& queens, vector<int>& king) {
bool arr[8][8]={false};
for(int i=0;i<queens.size();i++){
int a=queens[i][0];
int b=queens[i][1];
arr[a][b]=true;
}
int i=king[0],j=king[1];
for(int i=0;i<queens.size();i++){
queens.pop_back();
}
vector<int> pos;
while(j<8){
if(arr[i][j]){
pos[0]=i;
pos[1]=j;
queens.push_back(pos);
break;
}
j++;
}
i=king[0],j=king[1];
while(j>=0){
if(arr[i][j]){
pos[0]=i;
pos[1]=j;
queens.push_back(pos);
break;
}
j--;
}
i=king[0],j=king[1];
while(i<8){
if(arr[i][j]){
pos[0]=i;
pos[1]=j;
queens.push_back(pos);
break;
}
i++;
}
i=king[0],j=king[1];
while(i>=0){
if(arr[i][j]){
pos[0]=i;
pos[1]=j;
queens.push_back(pos);
break;
}
i--;
}
return queens;
}
int main(){
return 0;
}