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
| #include <iostream>
#include <vector>
#define MAP 101
#define MAX_DRAGON 20
#define MAX_GENERATION 10
using namespace std;
typedef struct Location {
int row;
int col;
}Location;
bool map[MAP][MAP];
int dragon[MAX_DRAGON][4];
int numOfdragon;
void dragonCurb();
void singleDragonCurb(int x, int y, int direction, int generation);
int checkCell();
int main() {
cin >> numOfdragon;
for (int i = 0; i < numOfdragon; i++)
cin >> dragon[i][0] >> dragon[i][1] >> dragon[i][2] >> dragon[i][3];
dragonCurb();
cout << checkCell();
}
void dragonCurb() {
for (int i = 0; i < numOfdragon; i++)
singleDragonCurb(dragon[i][0], dragon[i][1], dragon[i][2], dragon[i][3]);
}
void singleDragonCurb(int x, int y, int direction, int generation) {
vector<Location> v;
v.push_back({ y, x });
if (direction == 0) v.push_back({ y, x + 1 });
else if (direction == 1) v.push_back({ y - 1, x });
else if (direction == 2) v.push_back({ y, x - 1 });
else if (direction == 3) v.push_back({ y + 1, x });
for (int i = 0; i < generation; i++) {
for (int j = v.size() - 2; j >= 0; j--) {
int rowD = v[j].row - v[j + 1].row;
int colD = v[j].col - v[j + 1].col;
if (rowD == 1) //이전보다 아래
v.push_back({ v.back().row, v.back().col - 1 });
else if (rowD == -1) //이번보다 위
v.push_back({ v.back().row, v.back().col + 1 });
else if (colD == 1)
v.push_back({ v.back().row + 1, v.back().col });
else if (colD == -1)
v.push_back({ v.back().row -1, v.back().col });
}
}
for (int i = 0; i < v.size(); i++)
map[v[i].row][v[i].col] = true;
}
int checkCell() {
int count = 0;
for (int i = 0; i < MAP-1; i++) {
for (int j = 0; j < MAP-1; j++) {
if (map[i][j] && map[i + 1][j] && map[i][j + 1] && map[i + 1][j + 1])
count++;
}
}
return count;
}
|