问题描述
给定2维平面上n个整点的坐标,一条直线最多能过几个点?
输入格式
第一行一个整数n表示点的个数
以下n行,每行2个整数分别表示每个点的x,y坐标。输出格式
输出一个整数表示答案。
样例输入
5
0 0
1 1
2 2
0 3
2 3样例输出
3
数据规模和约定
n<=1500,数据保证不会存在2个相同的点。
点坐标在int范围内
import java.util.Scanner;
/**
* @author sjn
* @date 2022-2-14
*/
public class ALGO_967共线 {
//创建一个点类
static class Point {
int x;
int y;
public Point(int x, int y) {
this.x = x;
this.y = y;
}
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
Point[] points = new Point[n];
for (int i = 0; i < n; i++) {
points[i] = new Point(sc.nextInt(), sc.nextInt());
}
if (n < 3) {
System.out.pr

该博客探讨了如何在2维平面上找到一组整数坐标点中,通过一条直线最多可以经过多少个点的问题。通过Java编程解决,输入包含点的数量和每个点的坐标,输出为最多共线点的数量。样例输入和输出显示了当n=5时,最多3个点共线。题目保证n≤1500且无重复点,点坐标在int范围内。
最低0.47元/天 解锁文章
772

被折叠的 条评论
为什么被折叠?



