Skip to content

Instantly share code, notes, and snippets.

@Bekt
Created January 18, 2013 06:14
Show Gist options
  • Select an option

  • Save Bekt/4562708 to your computer and use it in GitHub Desktop.

Select an option

Save Bekt/4562708 to your computer and use it in GitHub Desktop.
3
09:00-09:50
13:00-17:00
09:50-10:30
2
10:00-11:00
09:00-12:00
1
00:00-23:59
1
00:00-00:01
1
23:58-23:59
2
10:00-11:00
10:00-11:00
5
10:00-11:01
11:00-12:01
12:00-13:01
13:00-14:01
14:00-15:01
5
14:00-15:01
13:00-14:01
12:00-13:01
11:00-12:01
10:00-11:01
5
10:01-11:01
11:01-12:01
12:01-13:01
13:01-14:01
14:01-15:01
100
19:00-19:12
19:12-19:24
19:24-19:36
19:36-19:48
19:48-20:00
18:00-18:12
18:12-18:24
18:24-18:36
18:36-18:48
18:48-19:00
17:00-17:12
17:12-17:24
17:24-17:36
17:36-17:48
17:48-18:00
16:00-16:12
16:12-16:24
16:24-16:36
16:36-16:48
16:48-17:00
15:00-15:12
15:12-15:24
15:24-15:36
15:36-15:48
15:48-16:00
14:00-14:12
14:12-14:24
14:24-14:36
14:36-14:48
14:48-15:00
13:00-13:12
13:12-13:24
13:24-13:36
13:36-13:48
13:48-14:00
12:00-12:12
12:12-12:24
12:24-12:36
12:36-12:48
12:48-13:00
11:00-11:12
11:12-11:24
11:24-11:36
11:36-11:48
11:48-12:00
10:00-10:12
10:12-10:24
10:24-10:36
10:36-10:48
10:48-11:00
09:00-09:12
09:12-09:24
09:24-09:36
09:36-09:48
09:48-10:00
08:00-08:12
08:12-08:24
08:24-08:36
08:36-08:48
08:48-09:00
07:00-07:12
07:12-07:24
07:24-07:36
07:36-07:48
07:48-08:00
06:00-06:12
06:12-06:24
06:24-06:36
06:36-06:48
06:48-07:00
05:00-05:12
05:12-05:24
05:24-05:36
05:36-05:48
05:48-06:00
04:00-04:12
04:12-04:24
04:24-04:36
04:36-04:48
04:48-05:00
03:00-03:12
03:12-03:24
03:24-03:36
03:36-03:48
03:48-04:00
02:00-02:12
02:12-02:24
02:24-02:36
02:36-02:48
02:48-03:00
01:00-01:12
01:12-01:24
01:24-01:36
01:36-01:48
01:48-02:00
00:00-00:12
00:12-00:24
00:24-00:36
00:36-00:48
00:48-01:00
0
import java.io.*;
import java.util.*;
//2012: http://www.ccsc-ms.org/2012_Problems/pdfs/G-overbooked.pdf
//Status: AC
public class overbooked {
static Scanner in;
public static void main(String[] args) throws Exception {
in = new Scanner(new File("overbooked.in"));
new overbooked().run();
}
void run() {
int n;
String line;
while ((n = in.nextInt()) != 0) {
in.nextLine();
List<Pair> list = new ArrayList<Pair>();
for (int i = 0; i < n; i++) {
line = in.nextLine();
int start = (Integer.valueOf(line.substring(0, 2)) * 60) + Integer.valueOf(line.substring(3, 5));
int finish = (Integer.valueOf(line.substring(6, 8)) * 60) + Integer.valueOf(line.substring(9));
list.add(new Pair(start, finish));
}
process(list);
}
}
void process(List<Pair> list) {
Collections.sort(list);
for (int i = 0; i < list.size() - 1; i++) {
if (list.get(i).finish > list.get(i + 1).start) {
System.out.println("conflict");
return;
}
}
System.out.println("no conflict");
}
class Pair implements Comparable<Object> {
Integer start, finish;
public Pair(int s, int f) {
start = s;
finish = f;
}
public int compareTo(Object o) {
Pair ob = (Pair) o;
int comp = finish.compareTo(ob.finish);
if (comp == 0)
comp = start.compareTo(ob.start);
return comp;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment