반응형
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 | #include <iostream> #include <algorithm> using namespace std; int n, m; int a[500000]; int bs(int x) { int r = n-1; int l = 0; while (l <= r) { int mid = (r + l) / 2; if (a[mid] == x) return 1; else if (a[mid] < x) l = mid + 1; else if (a[mid] > x) r = mid - 1; } return 0; } int main() { ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> n; for (int i = 0; i < n; i++) cin >> a[i]; sort(a,a+n); cin >> m; while (m--) { int x; cin >> x; cout << bs(x) << ' '; } } | cs |
'Algorithm' 카테고리의 다른 글
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 5576번:콘테스트 답 (0) | 2017.04.01 |
---|---|
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 2164번:카드 2 답 (0) | 2017.04.01 |
(C++) - 백준(BOJ) 11557번 : Yangjojang of the year 답 (0) | 2017.03.30 |
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 10102번:개표 답 (0) | 2017.03.30 |
C++(씨쁠쁠)(cplusplus)-백준(baekjoon)(BaekJoon)코딩 10819번:차이를 최대로 답 (0) | 2017.03.27 |