Algorithm/BOJ

[백준 알고리즘/C++/그리디] 2891 카약과 강풍

pinevienna 2021. 2. 15. 22:32

 

 

강풍이 불어 카약이 부숴졌다고 한다

여분의 카약을 들고온 팀이 바로 앞, 뒤 팀에게만 카약을 빌려줄 건데

준비한 카약도 부숴지고 빌리지도 못한 팀이 몇 팀인지 출력하는 문제

 

 

프로그래머스의 체육복과 아주아주 비슷한 문제다

그냥 주어만 바뀜

카약이 하나면 빌려줄 수 없다는 조건을 못봐서 한 번 틀렸다,,

 

 

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
#include <iostream>
#include <vector>
using namespace std;
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
 
    int n, s, r;
    vector<int> arr(111);
 
    cin >> n >> s >> r;
    
    int temp;
    while (s--) {
        cin >> temp;
        arr[temp]--;
    }
 
    while (r--) {
        cin >> temp;
        arr[temp]++;
 
        if (arr[temp] == 2 && arr[temp - 1== 0) arr[temp - 1]++;
        else if (arr[temp] == 2 && arr[temp + 1== 0) arr[temp + 1]++;
    }
 
    int res = 0;
    for (int i = 1; i <= n; i++)
        if (arr[i] == 0) res++;
    
    cout << res;
}
cs