链接:http://www.luogu.org/problem/show?pid=1142
题意:n个点,横坐标+纵坐标。判断最多有多少个点能再一条直线上(n <= 700)
解析:求任意两个点构成的直线的方程
化为一般式:ax+by+c=0 得:
a=y2-y1
b=x1-x2//注意别写反了
c=-ax1+by1
即可
不可思议的n = 700时n ^3也能过
#include <iostream>
#include <cstdio>
#include <cstring>
#include <sstream>
#include <string>
#include <algorithm>
#include <list>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
using namespace std;
int x[705],y[705];
int main()
{
//freopen("in.txt","r",stdin);
int n;
scanf("%d",&n);
for(int i = 0; i < n; i ++)
{
scanf("%d%d",&x[i],&y[i]);
}
if(n == 1){
printf("1\n");
return 0;}
int a,b,c;
int temp;
int ans = 1;
for(int i = 0; i < n; i ++)
{
for(int j = 0; j < i; j ++)
{
a= y[j] - y[i];
b = x[j] - x[i];
//C=-ax1+by1
c = -a*x[i] + b*y[i];
temp =0;
for(int t = 0; t < n; t ++)
{
if(a*x[t] -b*y[t] + c == 0)
{
temp ++;
// cout<<1<<endl;
}
}
// cout<<temp<<endl;
ans = max(ans,temp);
}
}
printf("%d\n",ans);
return 0;
}