-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5653.cpp
More file actions
123 lines (101 loc) Β· 2.01 KB
/
Copy path5653.cpp
File metadata and controls
123 lines (101 loc) Β· 2.01 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
116
117
118
119
120
121
122
123
#include <iostream>
#include <deque>
#include <algorithm>
using namespace std;
int n,m,k;
int map[301][301] = {0,};
bool chk[301][301] = {0,};
typedef struct
{
int y;
int x;
int life_time;
int curr_time;
}Cell;
deque<Cell> dq;
int dy[4] = {0,0,-1,1};
int dx[4] = {-1,1,0,0};
int cmp(Cell A, Cell B)
{
return A.life_time > B.life_time;
}
void init_(){
for(int i=0; i<301; i++)
for(int j=0; j<301; j++){
map[i][j] = 0;
chk[i][j] = false;
}
}
void print(deque<Cell>qq){
while(!qq.empty()){
cout<<qq.front().y<<", "<<qq.front().x<<": "<<qq.front().life_time<<" "<<qq.front().curr_time<<endl;
qq.pop_front();
}
cout<<endl<<endl;
}
void bfs(int y, int x, int time){
for(int k=0; k<time; k++){
int size = dq.size();
for(int i=0; i<size; i++){
y = dq.front().y; //μ’ν y
x = dq.front().x; //μ’ν x
int lt = dq.front().life_time; //μΈν¬μ μ°μ μμ
int ct = dq.front().curr_time; //μΈν¬μ λ¨μ μκ°
dq.pop_front();
if(ct > 1){
Cell temp;
temp.y = y;
temp.x = x;
temp.life_time = lt;
temp.curr_time = ct - 1;
dq.push_back(temp);
}
else if(ct == 1){
chk[y][x] = true;
for(int j=0; j<4; j++){
int ny = y + dy[j];
int nx = x + dx[j];
if(!chk[ny][nx]){
chk[ny][nx] = true;
Cell temp;
temp.y = ny;
temp.x = nx;
temp.life_time = lt;
temp.curr_time = lt;
dq.push_back(temp);
}
}
}
}
sort(dq.begin(), dq.end(), cmp);
print(dq);
}
}
int main(int argc, char const *argv[])
{
int t;
cin>>t;
for(int testcase=1; testcase<=t; testcase++){
cin>>n>>m>>k;
int N = 300/n;
int M = 300/m;
for(int i=0; i<n; i++)
for(int j=0; j<m; j++){
cin>>map[N+i][M+j];
if(map[N+i][M+j] != 0){
chk[N+i][M+j] = true;
Cell temp;
temp.y = N+i;
temp.x = M+j;
temp.life_time = map[N+i][M+j]*2;
temp.curr_time = map[N+i][M+j]*2;
dq.push_back(temp);
}
}
bfs(N,M,k);
cout<<dq.size()<<endl;
dq.clear();
init_();
}
return 0;
}