forked from improper4/uva
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUVa00231_TestingtheCATCHER.java
76 lines (65 loc) · 1.57 KB
/
UVa00231_TestingtheCATCHER.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
package uva;
/* USER: 46724 (sfmunera) */
/* PROBLEM: 167 (231 - Testing the CATCHER) */
/* SUBMISSION: 10165654 */
/* SUBMISSION TIME: 2012-05-28 20:43:23 */
/* LANGUAGE: 2 */
import java.util.*;
import java.io.*;
public class UVa00231_TestingtheCATCHER {
static int binSearch(List<Integer> A, int x) {
if (A.isEmpty())
return -1;
if (A.get(A.size() - 1) < x)
return -1;
int lo = 0;
int hi = A.size() - 1;
while (lo < hi) {
int mid = (lo + hi) / 2;
if (A.get(mid) <= x)
lo = mid + 1;
else
hi = mid;
}
return lo;
}
static List<Integer> lis(List<Integer> list) {
// Compute LIS
List<Integer> lis = new ArrayList<Integer>();
for (int i = 0; i < list.size(); ++i) {
int y = list.get(i);
int ind = binSearch(lis, y);
if (ind == -1)
lis.add(y);
else
lis.set(ind, y);
}
return lis;
}
public static void main(String[] args) throws IOException {
BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
int t = 1;
boolean first = true;
while (true) {
List<Integer> list = new ArrayList<Integer>();
while (true) {
int x = Integer.parseInt(in.readLine());
if (x == -1)
break;
list.add(-x);
}
if (list.isEmpty())
break;
List<Integer> lis = lis(list);
if (first)
first = false;
else
System.out.println();
System.out.println("Test #" + t + ":");
System.out.println(" maximum possible interceptions: " + lis.size());
++t;
}
in.close();
System.exit(0);
}
}