直线上最多的点的个数

/**
 * 题目:给出一个二维平面上的n个点,求最多有多少个点在同一条直线上。
 * 思路:求出直线表达式的三个系数a,b,c,将其余的点代入判断是否在此直线上
 * 应该还有更好的算法,暂时没想到
 * @author libin
 * @version 0.1
 */
public class Test01{
    public static void main(String[] args) {
        Point point = null;
        Point[] points = {
                point = new Point(1,2),
                point = new Point(3,6),
                point = new Point(4,6),
                point = new Point(4,8),
                point = new Point(0,0),
                point = new Point(1,3),
        };
        System.out.println(maxPionts(points));
    }
    public static int maxPionts(Point[] points){
        if(points == null || points.length == 0){
            return 0;
        }
        int result = 0;
        if(points.length == 1){
            return 1;
        }
        //第一层循环确定第一个点
        for(int i=0;iresult){
                    result = num;
                }
            }
        }
        return result;
    }
}
class Point{
    int x;
    int y;
    Point(){
        x=0;
        y=0;
    }
    Point(int x,int y){
        this.x = x;
        this.y = y;
    }
}

你可能感兴趣的:(java点滴积累,算法学习笔记,-,Java)