Skip to content

Instantly share code, notes, and snippets.

@niklasjang
Created April 19, 2020 07:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save niklasjang/1ce3800d7fb9fb94ad7dee9f7ddd107e to your computer and use it in GitHub Desktop.
Save niklasjang/1ce3800d7fb9fb94ad7dee9f7ddd107e to your computer and use it in GitHub Desktop.
[PS][이분탐색]/[BOJ][10815][숫자 카드]
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,t;
int card[500000];
int s, e, mid;
bool search(int x) {
return false;
}
int main(void) {
cin.tie(NULL);
ios::sync_with_stdio("false");
cin >> n;
for (int i = 0; i < n; i++) {
cin >> card[i];
}
cin >> m;
sort(card, card + n);
bool flag;
while(m--){
cin >> t;
//이분탐색
s = 0;
e = n - 1;
flag = false;
while (s <= e) {
mid = (s + e) / 2;
if (t == card[mid]){
flag = true;
break;
}
else if (t < card[mid]) {
e = mid - 1;
}
else {
s = mid + 1;
}
}
if (flag) cout << "1 ";
else cout << "0 ";
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment