-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest code
More file actions
98 lines (74 loc) · 1.67 KB
/
Copy pathtest code
File metadata and controls
98 lines (74 loc) · 1.67 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
#include <bits/stdc++.h>
using namespace std;
vector<string> split_string(string);
int check(int i,int j,int k, vector<vector<int>> obstacles)
{
int r;
for(r=0;r<k;++r)
if(obstacles[r][0]==j&&obstacles[r][1]==i)
return 0;
return 1;
}
int queensAttack(int n, int k, int r_q, int c_q, vector<vector<int>> obstacles) {
int count=0;
int i=r_q,j=c_q;
for(i=r_q+1,j=c_q+1;i<=n&&j<=n;i++,j++)
{
if(check(i,j,k,obstacles))
count++;
else break;
}
for(i=r_q-1,j=c_q-1;i>0&&j>0;i--,j--)
{
if(check(i,j,k,obstacles))
count++;
else break;
}
for(i=r_q+1,j=c_q-1;i<=n&&j>0;i++,j--)
{
if(check(i,j,k,obstacles))
count++;
else break;
}
for(i=r_q-1,j=c_q+1;i>0&&j<=n;i--,j++)
{
if(check(i,j,k,obstacles))
count++;
else break;
}
for(i=r_q+1,j=c_q;i<=n;i++)
{
if(check(i,c_q,k,obstacles))
count++;
else break;
}
for(i=r_q-1,j=c_q;i>0;i--)
{
if(check(i,c_q,k,obstacles))
count++;
else break;
}
for(j=c_q-1;j>0;j--)
{
if(check(r_q,j,k,obstacles))
count++;
else break;
}
for(j=c_q+1;j<=n;j++)
{
if(check(r_q,j,k,obstacles))
count++;
else break;
}
return count;
}
int main()
{
int n,k,r_q,c_q,i;
cin>>n>>k>>r_q>>c_q;
int pos[n][n];
for(i=0;i<k;++i)
{
cin>>tr>>tc;
pos[tr][tc]=1;
}