728x90
반응형
- 풀이 링크:
GitHub - xhaktmchl/Algorithm_study: 알고리즘 이론 및 문제풀이
알고리즘 이론 및 문제풀이. Contribute to xhaktmchl/Algorithm_study development by creating an account on GitHub.
github.com
#include <iostream>
#include <algorithm>
//#include <map> // 중복 x
//#include <string> // getline
//#include <cstring> // memset, strok, strstr
#include <vector>
//#include <queue>
//#include <set> // 트리, 중복 x
//#include <unordered_set>
using namespace std;
/*
[백준 10815 c++ VO] 숫자 카드
접근1:
시간복잡도:
풀이:
//1.입력
//2.정렬
//3.이진탐색
//4.출력: 있으면 1, 없으면 0
*/
int n,num,m,val;
vector<int> v;
int main()
{
ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(0);
//1.입력
cin >> n;
for (int i = 0; i < n; i++) {
cin >> num;
v.push_back(num);
}
//2.정렬
//3.이진탐색
//4.출력: 있으면 1, 없으면 0
sort(v.begin(), v.end());
cin >> m;
for (int i = 0; i < m; i++) {
cin >> val;
if (binary_search(v.begin(), v.end(), val)) cout << 1 << " ";
else cout << 0 << " ";
}
return 0;
}
반응형
'Algorithm_BOJ(백준) > 이진탐색' 카테고리의 다른 글
[백준 1920 c++ VOVO] 수 찾기 (0) | 2023.02.09 |
---|---|
[백준 2417 c++ X] 정수 제곱근 (0) | 2023.01.24 |
[백준 12738 c++ V] 가장 긴 증가하는 부분 수열 3 (0) | 2023.01.19 |
[백준 2143 c++ V] 두 배열의 합 (0) | 2023.01.11 |
[백준 2110 c++ V] 공유기 설치 (0) | 2021.08.07 |