- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path16235.java
More file actions
Latest commit
115 lines (93 loc) · 2.45 KB
/
Copy path16235.java
File metadata and controls
115 lines (93 loc) · 2.45 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
importjava.io.BufferedReader;
importjava.io.IOException;
importjava.io.InputStreamReader;
importjava.util.ArrayList;
importjava.util.Collections;
importjava.util.StringTokenizer;
publicclassMain {
staticclassTreeimplementsComparable<Tree>{
intx;
inty;
intage;
Tree(intx, inty, intage) {this.x=x; this.y=y; this.age=age;}
@Override
publicintcompareTo(Treeo) {
if(this.age > o.age)
return1;
elseif(this.age < o.age)
return -1;
else
return0;
}
}
publicstaticvoidmain(String[] args) throwsIOException {
BufferedReaderbr = newBufferedReader(newInputStreamReader(System.in));
StringTokenizerst = newStringTokenizer(br.readLine());
intn = Integer.parseInt(st.nextToken());
intm = Integer.parseInt(st.nextToken());
intk = Integer.parseInt(st.nextToken());
int[][] eatable = newint[n][n];
for(inti=0; i<n; i++)
for(intj=0; j<n; j++)
eatable[i][j] = 5;
int[][] gain = newint[n][n];
for(inti=0; i<n; i++) {
st = newStringTokenizer(br.readLine());
for(intj=0; j<n; j++) {
gain[i][j] = Integer.parseInt(st.nextToken());
}
}
ArrayList<Tree> alive = newArrayList<>(m);
for(inti=0; i<m; i++) {
st = newStringTokenizer(br.readLine());
intx = Integer.parseInt(st.nextToken());
inty = Integer.parseInt(st.nextToken());
intage = Integer.parseInt(st.nextToken());
alive.add(newTree(x-1, y-1, age));
}
Collections.sort(alive);
ArrayList<Tree> dead;
while(k-- > 0) {
dead = newArrayList<>();
ArrayList<Tree> alive_new = newArrayList<>();
// 봄
for(Treet : alive) {
if(t.age <= eatable[t.x][t.y]) {
eatable[t.x][t.y] -= t.age;
t.age++;
alive_new.add(t);
} else {
dead.add(t);
}
}
// 여름
for(Treet : dead) {
eatable[t.x][t.y] += t.age/2;
}
// 가을
ArrayList<Tree> born = newArrayList<>();
for(Treet : alive_new) {
if(t.age%5 == 0) {
for(inti=0; i<8; i++) {
intx = t.x+dx[i];
inty = t.y+dy[i];
if(x<0 || x>=n || y<0 || y>=n)
continue;
born.add(newTree(x, y, 1));
}
}
}
born.addAll(alive_new);
alive = born;
// 겨울
for(inti=0; i<n; i++) {
for(intj=0; j<n; j++) {
eatable[i][j] += gain[i][j];
}
}
}
System.out.println(alive.size());
}
staticint[] dx = {1, 0, -1, 0, 1, 1, -1, -1};
staticint[] dy = {0, 1, 0, -1, 1, -1, 1, -1};
}