728x90
https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRJ8EKe48DFAUo
SW Expert Academy
SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!
swexpertacademy.com
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
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
|
#include <iostream>
#include <cstring>
#define MAX 350
using namespace std;
int t, n, m, k;
int arr[MAX][MAX]; //입력
int cost[MAX][MAX]; //
int vitality[MAX][MAX];
int dy[4] = { 0, 0, 1, -1 };
int dx[4] = { 1, -1, 0, 0 };
bool check[MAX][MAX];
bool sibal[MAX][MAX];
bool die[MAX][MAX]; //죽은거
bool good[MAX][MAX]; //활성화
bool flag = false;
int search(int ystart, int xstart, int yend, int xend, int k) {
int cnt = 0;
while (cnt < k) {
cnt++;
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
if (arr[i][j] != 0 && check[i][j] == false) cost[i][j] = cost[i][j] + 1; // cost + 1
if (arr[i][j] == 0)
sibal[i][j] = true;
else sibal[i][j] = false; // false 면 절대 못바꿈
}
}
for (int i = ystart; i < yend; i++) {
for (int j = xstart; j < xend; j++) {
if (good[i][j] == true && die[i][j] == false) { // 활성화 되어 있고, 안죽었다
vitality[i][j]++;
for (int dir = 0; dir < 4; dir++) {
int y = i + dy[dir];
int x = j + dx[dir];
if (arr[y][x] >= 0 && check[y][x] == false && sibal[y][x] == true) {
if (flag == false) {
ystart = ystart - 1;
xstart = xstart - 1;
yend = yend + 1;
xend = xend + 1;
if (ystart < 0) ystart = 0;
if (xstart < 0) xstart = 0;
if (yend > 350) yend = 350;
if (xend > 350) xend = 350;
flag = true;
}
if (arr[y][x] < arr[i][j]) {
arr[y][x] = arr[i][j];
}
} check[i][j] = true;
}
if (vitality[i][j] == arr[i][j]) {
die[i][j] = true;
good[i][j] = false; //비활성화 시킴
}
}
}
}
flag = false;
for (int i = ystart; i < yend; i++) {
for (int j = xstart; j < xend; j++) {
if (cost[i][j] == arr[i][j] && arr[i][j] != 0 && check[i][j] == false) {
//다 자랐고, 0 이 아니다. check[i][j] 는 false
good[i][j] = true; //활성화
}
}
}
}
int num = 0;
for (int i = 0; i < MAX; i++) {
for (int j = 0; j < MAX; j++) {
//cout << arr[i][j] << " ";
if (arr[i][j]) {
if (!die[i][j] || good[i][j] == true) {
num++;
}
}
}//cout << endl;
}
return num;
}
int main() {
cin >> t;
for (int tc = 1; tc <= t; tc++) {
cin >> n >> m >> k;
int ystart = (MAX - n) / 2;
int xstart = (MAX - m) / 2;
int yend = ystart + n;
int xend = xstart + m;
int result = 0;
for (int i = ystart; i < yend; i++) {
for (int j = xstart; j < xend; j++) {
cin >> arr[i][j]; // 입력
// if (arr[i][j] != 0) check[i][j] = true;
}
}
result = search(ystart, xstart, yend, xend, k);
cout << "#" << tc << " " << result << endl;
memset(arr, 0, sizeof(arr));
memset(die, 0, sizeof(die));
memset(good, 0, sizeof(good));
memset(check, 0, sizeof(check));
memset(cost, 0, sizeof(cost));
memset(vitality, 0, sizeof(vitality));
memset(sibal, 0, sizeof(sibal));
}
//system("pause");
return 0;
}
|
728x90
'Algorithm Study > SWEA' 카테고리의 다른 글
(SWEA) 5656.[모의 sw 역량테스트] 벽돌 깨기 (0) | 2020.08.13 |
---|---|
(SWEA) 2112. [모의 SW 역량테스트] 보호 필름 (0) | 2020.07.03 |
(SWEA) 4014. [모의 SW 역량테스트] 활주로 건설 (0) | 2020.07.03 |
(SWEA) 4013. [모의 SW 역량테스트] 특이한 자석 (0) | 2020.05.07 |
(SWEA) 5658. [모의 SW 역량테스트] 보물상자 비밀번호 (0) | 2020.04.06 |
댓글