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

1952 수영장

by tryotto 2020. 1. 16.
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
    #include <stdio.h>
    #include <queue>
    #include <utility>
 
    using namespace std;
 
    int cost[5= { 0 };
    int month[15= { 0 };
 
    int bfs() {
        queue<pair<intint>> q;
        int cur = 1, minS = cost[4];
 
        q.push(make_pair(cur, 0));
 
        while (!q.empty()) {
            cur = q.front().first;
            int score = q.front().second;
        
            q.pop();
 
            if (cur > 12) {
                if (minS > score)
                    minS = score;
 
                continue;
            }
    
            //이용 안함
            if (month[cur] == 0
                q.push(make_pair(cur + 1, score));
            
            //1일 이용
            int day1 = score + month[cur] * cost[1];
            if (cur <= 12
                q.push(make_pair(cur + 1, day1));    
 
            //한 달 이용
            int month1 = score + cost[2];
            if (cur <= 12
                q.push(make_pair(cur + 1, month1));            
 
            //3달 이용
            int month3 = score + cost[3];
            if (cur <= 12
                q.push(make_pair(cur + 3, month3));            
        }
 
        return minS;
    }
 
    int main() {
        int t;
        scanf("%d"&t);
 
        int testN = 1;
        while (t--) {
            for (int i = 1; i <= 4; i++
                scanf("%d"&cost[i]);
            for (int i = 1; i <= 12; i++)
                scanf("%d"&month[i]);
        
            printf("#%d %d\n", testN, bfs());
            testN++;
        }
    }
cs



while 문 탈출 조건을 잘못 설정해서 계속 fail 했다.

특정 조건을 만족할때, continue; 로 처리했어야 했는데, 나는 아예 while문을 탈출하도록 해버렸다.
이 부분에서 문제가 생겼다


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

5658 보물상자 비밀번호  (0) 2020.03.02
5656 벽돌깨기  (0) 2020.03.02
5644 무선충전  (0) 2020.03.02
4008 숫자만들기  (0) 2020.01.16
4013 특이한 자석  (0) 2020.01.15