Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- bfs
- 컴공과
- 구현
- 브루트포스
- 정석
- 개발
- 백준
- 코테
- Operating System
- c++
- coding
- 너비우선탐색
- 오에스
- OS
- cs
- Stack
- 북리뷰
- vector
- 알고리즘
- 자료구조
- DP
- 그래프
- 컴퓨터공학과
- Computer science
- 스택
- 코딩
- 문제풀이
- 오퍼레이팅시스템
- 정석학술정보관
- 컴공
Archives
- Today
- Total
Little Jay
[C++] 백준 1920 수 찾기 본문
처음에 시간 초과가 떠서 봤더니
ios_base::sync_with_stdio(0);
cin.tie(0);
이거 두개 안해서 틀렸었다.
항상 시간 초과가 나면 킹받는다.
이분(이진)탐색 즉, Binary Search를 이용하는 문제이다
자료구조를 배우긴 했지만 Binary Search를 배우지는 않아서
algorithm 헤더에 있는 binary_search 메소드를 사용했다
이 부분 구현은 혼자 따로 해봐야 겠다
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int n, m, x;
cin >> n;
vector<int> v;
for (int i = 0; i < n; i++) {
cin >> x;
v.push_back(x);
}
cin >> m;
sort(arr, arr + n);
sort(v.begin(), v.end());
for (int i = 0; i < m; i++) {
cin >> x;
if (binary_search(v.begin(), v.end(), x))
cout << 1 << "\n";
else
cout << 0 << "\n";
}
return 0;
}
'알고리즘 > BOJ' 카테고리의 다른 글
[C++] 백준 2749번 피보나치 수 3 (0) | 2021.07.23 |
---|---|
[C++] 백준 9471번 피사노 주기 (0) | 2021.07.23 |
[C++] 백준 15829번 Hashing (0) | 2021.07.18 |
[C++] 백준 10816번 숫자 카드 2 (0) | 2021.07.18 |
[C++] 백준 5054번 주차의 신 (0) | 2021.07.16 |
Comments