구현(Implementation)

백준 1773번: 폭죽쇼

cepiloth 2018. 8. 3. 16:58
반응형

https://www.acmicpc.net/problem/1773


1. 문제

학생들은 3주가 지난 기념으로 매점에서 1월 1일이 지나 싸게 파는 폭죽을 사서 터뜨리고 있다.


폭죽쇼를 하는 동안 N명의 학생들이 폭죽을 터뜨린다. 그리고 이 N명의 학생은 각각 일정한 주기로 폭죽을 터뜨린다. 물론 이 주기는 학생들마다 같을 수도, 다를 수도 있다. 그리고 우리는 초 단위로 관찰을 하고, 폭죽 역시 초 단위로 터진다.


폭죽쇼가 끝날 때까지 얼마나 많은 시간동안 밤하늘에 폭죽이 터지는 것을 볼 수 있는지 궁금해 하는 조교를 도와주자.


2. 알고리즘

키워드 - 구현


3. 코드


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
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <math.h>
#include <memory.h>
 
using namespace std;
 
#define MAX_SIZE 100
#define INF 0x7fffffff
#define CENDL "\n"
#define ll long long
 
int main() {
    
    cin.tie(0);
    std::ios::sync_with_stdio(false);
 
    int n, c; cin >> n >> c;
 
    vector<int> arr(n);
    for (int i=0; i<n; i++) {
        cin >> arr[i];
    }
 
    int sol = 0;
    for (int i = 1; i<=c; i++) {
 
        int cand = 0;
        for (int j=0; j<n; j++) {
            if (i % arr[j] == 0) {
                cand++;
            }
        }
 
        if (cand) {
            sol++;
        }
    }
 
    cout << sol << CENDL;
 
    return 0;
}
cs

반응형