|
| 1 | +``` |
| 2 | +import java.io.*; |
| 3 | +import java.util.*; |
| 4 | +
|
| 5 | +public class Main { |
| 6 | + private static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); |
| 7 | + private static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); |
| 8 | + private static List<Event> events; |
| 9 | + private static int N; |
| 10 | + public static void main(String[] args) throws IOException { |
| 11 | + init(); |
| 12 | + int answer = sweep(); |
| 13 | +
|
| 14 | + bw.write(answer + "\n"); |
| 15 | + bw.flush(); |
| 16 | + bw.close(); |
| 17 | + br.close(); |
| 18 | + } |
| 19 | +
|
| 20 | + private static void init() throws IOException { |
| 21 | + N = Integer.parseInt(br.readLine()); |
| 22 | +
|
| 23 | + events = new ArrayList<>(); |
| 24 | +
|
| 25 | + for (int i = 1; i <= N; i++) { |
| 26 | + StringTokenizer st = new StringTokenizer(br.readLine()); |
| 27 | + int x1 = Integer.parseInt(st.nextToken()); |
| 28 | + int y1 = Integer.parseInt(st.nextToken()); |
| 29 | + int x2 = Integer.parseInt(st.nextToken()); |
| 30 | + int y2 = Integer.parseInt(st.nextToken()); |
| 31 | +
|
| 32 | + double angle1 = Math.atan2(y1, x1); |
| 33 | + double angle2 = Math.atan2(y2, x2); |
| 34 | +
|
| 35 | + if (angle1 > angle2) { |
| 36 | + double temp = angle1; |
| 37 | + angle1 = angle2; |
| 38 | + angle2 = temp; |
| 39 | + } |
| 40 | +
|
| 41 | + events.add(new Event(angle1, i, true)); |
| 42 | + events.add(new Event(angle2, i, false)); |
| 43 | + } |
| 44 | +
|
| 45 | + events.sort((o1, o2) -> { |
| 46 | + if (o1.angle == o2.angle) { |
| 47 | + if (o1.start != o2.start) return o1.start ? -1 : 1; |
| 48 | + return 0; |
| 49 | + } |
| 50 | +
|
| 51 | + return Double.compare(o1.angle, o2.angle); |
| 52 | + }); |
| 53 | + } |
| 54 | +
|
| 55 | + private static int sweep() { |
| 56 | + int result = 0; |
| 57 | + int count = 0; |
| 58 | +
|
| 59 | + for (Event event : events) { |
| 60 | + if (event.start) { |
| 61 | + count++; |
| 62 | + result = Math.max(result, count); |
| 63 | + } else { |
| 64 | + count--; |
| 65 | + } |
| 66 | + } |
| 67 | +
|
| 68 | + return result; |
| 69 | + } |
| 70 | +
|
| 71 | + static class Event { |
| 72 | + double angle; |
| 73 | + int index; |
| 74 | + boolean start; |
| 75 | +
|
| 76 | + public Event(double angle, int index, boolean start) { |
| 77 | + this.angle = angle; |
| 78 | + this.index = index; |
| 79 | + this.start = start; |
| 80 | + } |
| 81 | + } |
| 82 | +} |
| 83 | +``` |
0 commit comments