-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNo_1920.java
More file actions
61 lines (50 loc) · 1.55 KB
/
No_1920.java
File metadata and controls
61 lines (50 loc) · 1.55 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/*
Problem_1920_수 찾기
https://www.acmicpc.net/problem/1920
자료구조 : Binary Search
*/
import java.io.*;
import java.util.*;
public class No_1920 {
private static int[] a;
private static int left;
private static int right;
private static int mid;
private static int binarySearch(int check) {
while (right >= left) {
if (check == a[mid]) {
return 1;
}
if (check > a[mid]) {
left = mid + 1;
mid = (left + right) / 2;
} else {
right = mid - 1;
mid = (left + right) / 2;
}
}
return 0;
}
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
int num = Integer.parseInt(br.readLine());
StringTokenizer st = new StringTokenizer(br.readLine(), " ");
a = new int[num];
for (int i = 0; i < num; i++) {
a[i] = Integer.parseInt(st.nextToken());
}
Arrays.sort(a);
int m = Integer.parseInt(br.readLine());
st = new StringTokenizer(br.readLine(), " ");
for (int i = 0; i < m; i++) {
left = 0;
right = a.length - 1;
mid = (left + right) / 2;
bw.append(binarySearch(Integer.parseInt(st.nextToken())) + "\n");
}
bw.flush();
bw.close();
br.close();
}
}