Created
April 19, 2020 07:55
-
-
Save niklasjang/1ce3800d7fb9fb94ad7dee9f7ddd107e to your computer and use it in GitHub Desktop.
[PS][이분탐색]/[BOJ][10815][숫자 카드]
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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