結果
| 問題 | No.1041 直線大学 | 
| コンテスト | |
| ユーザー |  tenten | 
| 提出日時 | 2022-09-13 18:37:38 | 
| 言語 | Java (openjdk 23) | 
| 結果 | 
                                AC
                                 
                             | 
| 実行時間 | 69 ms / 2,000 ms | 
| コード長 | 2,219 bytes | 
| コンパイル時間 | 2,525 ms | 
| コンパイル使用メモリ | 77,656 KB | 
| 実行使用メモリ | 38,024 KB | 
| 最終ジャッジ日時 | 2024-11-16 08:14:42 | 
| 合計ジャッジ時間 | 4,963 ms | 
| ジャッジサーバーID (参考情報) | judge3 / judge5 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 3 | 
| other | AC * 37 | 
ソースコード
import java.io.*;
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner();
        int n = sc.nextInt();
        Point[] points = new Point[n];
        for (int i = 0; i < n; i++) {
            points[i] = new Point(sc.nextInt(), sc.nextInt());
        }
        int max = 0;
        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                Line line = points[i].getLine(points[j]);
                int count = 0;
                for (int k = j + 1; k < n; k++) {
                    if (line.contains(points[k])) {
                        count++;
                    }
                }
                max = Math.max(max, count + 2);
            }
        }
        System.out.println(max);
    }
    
    static class Point {
        int x;
        int y;
        
        public Point(int x, int y) {
            this.x = x;
            this.y = y;
        }
        
        public Line getLine(Point p) {
            return new Line(y - p.y, x - p.x, x, y);
        }
    }
    
    static class Line {
        int a;
        int b;
        int x;
        int y;
        
        public Line(int a, int b, int x, int y) {
            this.a = a;
            this.b = b;
            this.x = x;
            this.y = y;
        }
        
        public boolean contains(Point p) {
            return a * (p.x - x) - b * (p.y - y) == 0;
        }
    }
}
    
class Scanner {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    StringTokenizer st = new StringTokenizer("");
    StringBuilder sb = new StringBuilder();
    
    public Scanner() throws Exception {
        
    }
    
    public int nextInt() throws Exception {
        return Integer.parseInt(next());
    }
    
    public long nextLong() throws Exception {
        return Long.parseLong(next());
    }
    
    public double nextDouble() throws Exception {
        return Double.parseDouble(next());
    }
    
    public String next() throws Exception {
        while (!st.hasMoreTokens()) {
            st = new StringTokenizer(br.readLine());
        }
        return st.nextToken();
    }
    
}
            
            
            
        