-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcodejam.java
More file actions
68 lines (65 loc) · 1.95 KB
/
codejam.java
File metadata and controls
68 lines (65 loc) · 1.95 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
62
63
64
65
66
67
68
import java.io.*;
import java.util.*;
public class codejam {
public static void main(String[] args) throws IOException
{
Scanner r = new Scanner(System.in);
int cases = Integer.parseInt(r.nextLine());
StringTokenizer st;
int activities;
for(int i = 1; i <= cases; i++)
{
activities = Integer.parseInt(r.nextLine());
Activity[] sched = new Activity[activities];
for(int j = 0; j < activities; j++)
{
st = new StringTokenizer(r.nextLine());
int start = Integer.parseInt(st.nextToken());
int end = Integer.parseInt(st.nextToken());
sched[j] = new Activity(start, end);
}
ArrayList<Activity> cam = new ArrayList<Activity>();
ArrayList<Activity> jam = new ArrayList<Activity>();
String out = "";
for(Activity a: sched)
{
if(fine(a, cam))
{
out = out + "C";
cam.add(a);
}
else if(fine(a, jam))
{
out = out + "J";
jam.add(a);
}
else
{
out = "IMPOSSIBLE";
break;
}
}
System.out.println("Case #" + i + ": " + out);
}
}
public static boolean fine(Activity ac, ArrayList<Activity> person)
{
if(person.size() > 0) {
for (Activity a : person) {
if (!((ac.start >= a.end && ac.end >= a.end) || (ac.start <= a.start && ac.end <= a.start)))
return false;
}
}
return true;
}
}
class Activity
{
int start;
int end;
public Activity(int s, int e)
{
start = s;
end = e;
}
}