본문 바로가기
삼성 코팅테스트 준비/모의 역량 테스트 문제

5644 무선충전

by tryotto 2020. 3. 2.
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
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
#include <stdio.h>
#include <memory>
#include <math.h>
#include <algorithm>
#include <string.h>
 
using namespace std;
 
// place[i][]: 1=x, 2=y, 3=charge, 4=place
int place[101][5= { 0 };
int arr[101], brr[101];
// map[x][y][charge]
int map[11][11][3= { 0 };
int map_idx[11][11][3= { 0 };
int curA_x, curA_y, curB_x, curB_y;
 
int charging(int time);
void mapping(int m);
void input_charge(int y, int x, int c, int m);
void change_cur(int* y, int* x, int dir);
 
int main() {
    int t_case;
    scanf("%d"&t_case);
 
    for (int t = 1; t <= t_case; t++) {
        memset(arr, 0sizeof(arr));
        memset(brr, 0sizeof(brr));
        memset(place, 0sizeof(place));
        memset(map, 0sizeof(map));
        memset(map_idx, 0sizeof(map_idx));
        curA_x = 1, curA_y = 1, curB_x = 10, curB_y = 10;
 
        int m, a;
        scanf("%d %d"&m, &a);
 
        
        for (int i = 1; i <= m; i++)
            scanf("%d"&arr[i]);
        for (int i = 1; i <= m; i++)
            scanf("%d"&brr[i]);
 
        for (int i = 1; i <= a; i++) {
            scanf("%d %d %d %d"&place[i][1], &place[i][2], &place[i][3], &place[i][4]);
            mapping(i);
        }
 
        
        int rst = 0;
        int bef = 0;
        for (int i = 0; i <= m; i++) {
            rst += charging(i);
        //    printf("%d) rst: %d\n",i, rst-bef);
            bef = rst;
        }
        printf("#%d %d\n", t, rst);
    }
}
 
// place[i][]: 1=x, 2=y, 3=charge, 4=val
void mapping(int m) {
    int x = place[m][1];
    int y = place[m][2];
    int c = place[m][3];
    int v = place[m][4];
 
    for (int i = x - c; i <= x + c; i++) {
        if (i <= 0 || i > 10)
            continue;
        int xlen = abs(x - i);
        int ylen = c - xlen;
        for (int j = y - ylen; j <= y + ylen; j++) {
            if (j <= 0 || j > 10)
                continue;
            input_charge(i, j, v, m);
        }        
    }    
}
 
void input_charge(int x, int y, int c, int m) {
    int first = map[y][x][1];
    int first_idx = map_idx[y][x][1];
    int second = map[y][x][2];
    int second_idx = map_idx[y][x][2];
 
    if (c >= first) {
        second = first;
        second_idx = first_idx;
        first = c;
        first_idx = m;
    }
    else if (c >= second) {
        second = c;
        second_idx = m;
    }
 
    map[y][x][1= first;
    map_idx[y][x][1= first_idx;
    map[y][x][2= second;
    map_idx[y][x][2= second_idx;
}
 
void change_cur(int* x, int* y, int dir) {
    switch (dir) {
        case 0:
            break;
        case 1:
            *= *- 1;
            break;
        case 2:
            *= *+ 1;            
            break;
        case 3:
            *= *+ 1;
            break;
        case 4:
            *= *- 1;
            break;
    }
}
 
int charging(int time) {
    int dirA = arr[time];
    int dirB = brr[time];
 
    change_cur(&curA_x, &curA_y, dirA);
    change_cur(&curB_x, &curB_y, dirB);
 
    int place_A_1 = map_idx[curA_y][curA_x][1];
    int place_A_2 = map_idx[curA_y][curA_x][2];
    int place_B_1 = map_idx[curB_y][curB_x][1];
    int place_B_2 = map_idx[curB_y][curB_x][2];
 
    int rst = 0;
    if (place_A_1 != place_B_1) {        
        rst += (place[place_A_1][4+ place[place_B_1][4]);
    }
    else {
        if ((place_A_2 == 0&& (place_B_2 == 0)) {
            rst += place[place_A_1][4];
        }
        else if ((place_A_2 != 0&& (place_B_2 != 0)) {
            int tmpV_1 = place[place_A_1][4+ place[place_B_2][4];
            int tmpV_2 = place[place_A_2][4+ place[place_B_1][4];
 
            rst += max(tmpV_1, tmpV_2);
        }
        else {
            rst += (place[place_A_1][4+ place[place_A_2][4+ place[place_B_2][4]);
        }
    }
 
    return rst;
}
 
 
cs


1. 반드시, 테스트케이스가 시작할때 한번에 다 모아서 memset 을 해주자 (그리고, memset 은 string.h 의 함수다)

2. 발상에 좀 애를 먹었다. 이걸 1시간 내에 풀수 있을까.. 하하..


'삼성 코팅테스트 준비 > 모의 역량 테스트 문제' 카테고리의 다른 글

5658 보물상자 비밀번호  (0) 2020.03.02
5656 벽돌깨기  (0) 2020.03.02
4008 숫자만들기  (0) 2020.01.16
1952 수영장  (0) 2020.01.16
4013 특이한 자석  (0) 2020.01.15