-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathcd.java
95 lines (61 loc) · 1.95 KB
/
cd.java
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
import java.util.ArrayList;
import java.util.HashSet;
import java.util.TreeSet;
public class CD
{
public static int BS(ArrayList<Integer> nums, int target)
{
int max = nums.size();
int min = -1;
for(int i=0; i < Math.ceil(Math.log(nums.size()) / Math.log(2)); i++)
{
int index = (max + min) / 2;
if(min + 1 == max)
{
break;
}
if(nums.get(index) == target)
{
return index;
}
else if(nums.get(index) > target)
{
max = index;
}
else
{
min = index;
}
}
return -1;
}
public static void main(String[] args)
{
Kattio scan = new Kattio(System.in);
mainloop :while(scan.hasMoreTokens())
{
int ja = scan.getInt();
int ji = scan.getInt();
if(ja == 0 & ji == 0)
{
break mainloop;
}
TreeSet<Integer> jack = new TreeSet<>();
ArrayList<Integer> jill = new ArrayList<>();
for(int i=0; i < ja; i++)
{
jack.add(scan.getInt());
}
for(int i=0; i < ji; i++)
{
jill.add(scan.getInt());
}
int c = 0;
for(int i=0; i < Math.min(jill.size(), jack.size()); i++)
{
if(jack.contains(jill.get(i)))c++;
}
System.out.println(c);
}
}
}