2382. [모의 SW 역량테스트] 미생물 격리

SW 업무 관련/SW Expert Academy

2382. [모의 SW 역량테스트] 미생물 격리

WillBe_ 2018. 10. 10. 23:56

Thanks to 갓무새!!!!



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
#include <stdio.h>
#include <string.h>
 
typedef struct
{
    int y, x, num, direction;
}bio;
 
int map[101][101][2];
int N, M, K;
bio B[1004];
 
void Go(int *y, int *x, int *num, int *d)
{
    switch (*d)
    {
    case 1://상
        *-= 1;
        break;
    case 2://하
        *+= 1;
        break;
    case 3://좌
        *-= 1;
        break;
    case 4://우
        *+= 1;
        break;
    }
 
    if (*== 0 && *== 1)
    {
        *num /= 2;
        *= 2;
    }
    else if (*== N - 1 && *== 2)
    {
        *num /= 2;
        *= 1;
    }
    else if (*== 0 && *== 3)
    {
        *num /= 2;
        *= 4;
    }
    else if (*== N - 1 && *== 4)
    {
        *num /= 2;
        *= 3;
    }
    return;
}
 
 
 
int main()
{
    int Test_Case;
    scanf("%d"&Test_Case);
 
    for (int T = 1; T <= Test_Case; T++)
    {
        memset(map, 0sizeof(map));
        memset(B, 0sizeof(B));
        scanf("%d %d %d"&N, &M, &K);
 
        for (int i = 1; i <= K; i++)
        {
            scanf("%d %d %d %d"&B[i].y, &B[i].x, &B[i].num, &B[i].direction);
        }
 
        for (int t = 0; t < M; t++)
        {
            memset(map, 0sizeof(map));
            for (int i = 1; i <= K; i++)
            {
                if (B[i].num == 0)
                    continue;
 
                Go(&B[i].y, &B[i].x, &B[i].num, &B[i].direction);
 
                //map에 미생물이 없을 경우
                if (map[B[i].y][B[i].x][0== 0)
                {
                    map[B[i].y][B[i].x][0= i;
                    map[B[i].y][B[i].x][1= B[i].num;
                }
                //미생물이 있을 경우
                else if (map[B[i].y][B[i].x][0!= 0)
                {
                    //맵에 있는 미생물의 개수가 현재 보다 클 경우.
                    if (map[B[i].y][B[i].x][1> B[i].num)
                    {
                        B[map[B[i].y][B[i].x][0]].num += B[i].num;
 
                        B[i].num = B[i].direction = 0;
                    }
                    //맵에 있는 미생물의 개수가 현재 보다 작을 경우.
                    else if (map[B[i].y][B[i].x][1<  B[i].num)
                    {
                        //기존 맵의 미생물의 num을 임시 저장.
                        int Te = B[map[B[i].y][B[i].x][0]].num;
 
                        //기존 맵의 군집을 reset
                        B[map[B[i].y][B[i].x][0]].num = 0;
                        B[map[B[i].y][B[i].x][0]].direction = 0;
 
                        //맵에 현재 미생물 군집의 정보를 대입
                        map[B[i].y][B[i].x][0= i;
                        map[B[i].y][B[i].x][1= B[i].num;
 
                        //기존 군집을 흡수
                        B[i].num += Te;
                    }
                }
            }
        }
 
        int total = 0;
        for (int i = 1; i <= K; i++)
        {
            if (B[i].num)
            {
                total += B[i].num;
            }
        }
 
 
        printf("#%d %d\n", T, total);
    }
 
    return 0;
}
 
cs