티스토리 뷰

카테고리 없음

[SWEA 5653번] 줄기세포배양

집돌이탈출 2019. 2. 18. 02:00


[SWEA 5653번 줄기세포배양 URL]

https://www.swexpertacademy.com/main/code/problem/problemDetail.do



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
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Queue;
import java.util.Set;
import java.util.StringTokenizer;
 
public class Solution {
 
    public static int tCase, N, M, K;
    public static Node[][][] map;
    public static int[] dirX = new int[] { 00-11 };
    public static int[] dirY = new int[] { -1100 };
 
    public static void main(String[] args) throws Exception {
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        tCase = Integer.parseInt(br.readLine());
 
        for (int tc = 1; tc <= tCase; tc++) {
 
            StringTokenizer st = new StringTokenizer(br.readLine());
            N = Integer.parseInt(st.nextToken());
            M = Integer.parseInt(st.nextToken());
            K = Integer.parseInt(st.nextToken());
 
            map = new Node[2][360][360];
 
            for (int i = 151; i < N + 151; i++) {
                st = new StringTokenizer(br.readLine());
                for (int j = 151; j < M + 151; j++) {
                    int life = Integer.parseInt(st.nextToken());
                    if (life > 0)
                        map[0][i][j] = new Node(life, 00);
                }
            }
 
            int curMap = 0;
            for (int t = 0; t < K; t++) {
 
                for (int i = 0; i < N + 305; i++) {
 
                    for (int j = 0; j < M + 305; j++) {
 
                        if (map[curMap][i][j] == null)
                            continue;
 
                        if (map[curMap][i][j].state == 0) { // 비활성
 
                            map[curMap][i][j].time += 1;
                            if (map[curMap][i][j].time == map[curMap][i][j].life)
                                map[curMap][i][j].state = 1;
 
                            map[1 - curMap][i][j] = new Node(map[curMap][i][j].life, map[curMap][i][j].time,
                                    map[curMap][i][j].state);
 
                        } else if (map[curMap][i][j].state == 1) { // 활성
                            if (map[curMap][i][j].time == map[curMap][i][j].life) {
                                
                                for (int k = 0; k < 4; k++) {
                                    int nr = i + dirX[k];
                                    int nc = j + dirY[k];
                                    if (map[curMap][nr][nc] == null) {
                                        if (map[1 - curMap][nr][nc] == null) {
                                            map[1 - curMap][nr][nc] = new Node(map[curMap][i][j].life, 00);
                                        } else {
                                            if (map[1 - curMap][nr][nc].state == 0
                                                    && map[1 - curMap][nr][nc].life < map[curMap][i][j].life)
                                                map[1 - curMap][nr][nc] = new Node(map[curMap][i][j].life, 00);
                                        }
                                    }
                                }
                            }
 
                            map[curMap][i][j].time += 1;
                            if (map[curMap][i][j].time == map[curMap][i][j].life * 2)
                                map[curMap][i][j].state = 2;
                            map[1 - curMap][i][j] = new Node(map[curMap][i][j].life, map[curMap][i][j].time,
                                    map[curMap][i][j].state);
 
                        } else if (map[curMap][i][j].state == 2) { // 죽음
                            map[1 - curMap][i][j] = new Node(map[curMap][i][j].life, map[curMap][i][j].time,
                                    map[curMap][i][j].state);
                        }
                    }
                }
                curMap = 1 - curMap;    
            }
 
            int ans = 0;
            for (int i = 0; i < N + 305; i++) {
 
                for (int j = 0; j < M + 305; j++) {
                    if (map[curMap][i][j] != null && map[curMap][i][j].state != 2)
                        ans += 1;
                }
            }
            System.out.println("#" + tc + " " + ans);
        }
    }
}
 
class Node {
 
    int life;
    int time;
    int state;
 
    public Node(int life, int time, int state) {
        super();
        this.life = life;
        this.time = time;
        this.state = state;
    }
 
}
 
cs


댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
«   2024/12   »
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
글 보관함