问题描述
给你n个点,求最多有多少点共线
样例输入
6
7 122
8 139
9 156
10 173
11 190
-100 1
样例输出
5
算法讨论
枚举两个点,再枚举另一个点,判断是否在一条线上(直线,非线段),在就加一,保留最大值。
const
maxn=200;
var
a:array[1..maxn,1..2] of longint;
i,j,k,n,s,max:longint;
function cp(x1,y1,x2,y2,x,y:longint):longint;
var
ans:longint;
begin
ans:=(x1-x)*(y2-y)-(x2-x)*(y1-y);
exit(ans)
end;
begin
read(n);
for i:=1 to n do
read(a[i,1],a[i,2]);
for i:=1 to n-1 do
for j:=i+1 to n do
begin
s:=2;
for k:=1 to n do
if (i<>k) and (j<>k)
then if cp(a[j,1],a[j,2],a[k,1],a[k,2],a[i,1],a[i,2])=0
then inc(s);
if s>max
then max:=s
end;
write(max)
end.
Pixiv ID:61831844