-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1986.cpp
More file actions
115 lines (107 loc) · 1.68 KB
/
1986.cpp
File metadata and controls
115 lines (107 loc) · 1.68 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
// 1986. 체스
// 2019.05.19
// 시뮬레이션
#include<iostream>
#include<vector>
using namespace std;
int map[1001][1001];
// 나이트의 이동
int dx[8] = { -2,-2,-1,1,2,2,1,-1 };
int dy[8] = { -1,1,2,2,1,-1,-2,-2 };
// 퀸의이동
int dx2[8] = { -1,-1,-1,0,1,1,1,0 };
int dy2[8] = { -1,0,1,1,1,0,-1,-1 };
struct chess
{
int x;
int y;
int type; // 1.나이트 2.퀸
};
vector<chess> v;
int main()
{
int n, m;
cin >> n >> m;
// 퀸
int q;
cin >> q;
for (int i = 0; i < q; i++)
{
int x, y;
cin >> x >> y;
map[x][y] = 2;
v.push_back({ x,y,2 });
}
// 나이트
int k;
cin >> k;
for (int i = 0; i < k; i++)
{
int x, y;
cin >> x >> y;
map[x][y] = 1;
v.push_back({ x,y,1 });
}
// 폰
int p;
cin >> p;
for (int i = 0; i < p; i++)
{
int x, y;
cin >> x >> y;
map[x][y] = 3;
}
for (int i = 0; i < v.size(); i++)
{
// 퀸
if (v[i].type == 2)
{
int x = v[i].x;
int y = v[i].y;
for (int j = 0; j < 8; j++)
{
int cnt = 1;
while (1)
{
int xx = x + dx2[j] * cnt;
int yy = y + dy2[j] * cnt;
if (xx <= 0 || yy <= 0 || xx > n || yy > m || map[xx][yy] == 2 || map[xx][yy] == 3 || map[xx][yy] == 1)
{
break;
}
map[xx][yy] = 4;
cnt++;
}
}
}
// 나이트
else if (v[i].type == 1)
{
int x = v[i].x;
int y = v[i].y;
for (int j = 0; j < 8; j++)
{
int xx = x + dx[j];
int yy = y + dy[j];
if (xx <= 0 || yy <= 0 || xx > n || yy > m || map[xx][yy] != 0)
{
continue;
}
map[xx][yy] = 3;
}
}
}
int ans = 0;
for (int i = 1; i <= n; i++)
{
for (int j = 1; j <= m; j++)
{
if (map[i][j] == 0)
{
ans++;
}
}
}
cout << ans << "\n";
return 0;
}