-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path5648.cpp
More file actions
99 lines (84 loc) Β· 2.14 KB
/
Copy path5648.cpp
File metadata and controls
99 lines (84 loc) Β· 2.14 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
#include <iostream>
#include <vector>
using namespace std;
#define BASE 1000
#define MAX 4001
typedef struct
{
int x;
int y;
int dir;
int E;
int stat;
}Atom;
int map[MAX][MAX];
vector <Atom> atoms;
int K = 0;
int dy[4] = {1,-1,0,0};
int dx[4] = {0,0,-1,1};
bool check(int y, int x){
if(y<0 || x<0 || y>4000 || x>4000)
return true;
return false;
}
void simulator(){
while(!atoms.empty()){
int size = atoms.size();
//μμ μ΄λ
for(int i=0; i<size; i++){
map[atoms[i].y][atoms[i].x] = 0;
int dir = atoms[i].dir;
int nx = atoms[i].x + dx[dir];
int ny = atoms[i].y + dy[dir];
//λ²μλ₯Ό λ²μ΄λλ©΄ μλ©Έ
if(check(ny,nx)){
atoms[i].stat = 0;
continue;
}
//μ’ν μ¬μ€μ
atoms[i].x = nx;
atoms[i].y = ny;
//νμ¬ μμμ μ’νμ μμμ μλμ§ νμ
map[ny][nx] += atoms[i].E;
}
//μΆ©λνμΈ
for(int i=0; i<size; i++){
if(atoms[i].stat == 0)
continue;
if(map[atoms[i].y][atoms[i].x] != atoms[i].E){
K += map[atoms[i].y][atoms[i].x];
map[atoms[i].y][atoms[i].x] = 0;
atoms[i].stat = 0;
}
}
vector<Atom> temp;
temp.assign(atoms.begin(),atoms.end());
atoms.clear();
//λ²μ λ°μ μμ μ κ±°
for(int i=0; i<size; i++)
if(temp[i].stat != 0)
atoms.push_back(temp[i]);
}
}
int main(){
int test_case;
cin>>test_case;
for(int T=1; T<=test_case; T++){
int n;
cin>>n;
for(int i=0; i<n; i++){
Atom atom;
cin>>atom.x>>atom.y>>atom.dir>>atom.E;
atom.x += BASE;
atom.y += BASE;
atom.x *= 2;
atom.y *= 2;
atom.stat = 1;
atoms.push_back(atom);
}
simulator();
cout<<"#"<<T<<" "<<K<<endl;
K = 0;
}
return 0;
}γ΄