Description
Input
Output
Sample Input
6 7 122 8 139 9 156 10 173 11 190 -100 1
Sample Output
5
思路:直接暴力枚举n^3,然后用那啥判断一下,等于0就是了(不懂的请自行证明或移步到计算机几何去看)
注意:数据规模很水!!!但数组要开大(我加了个优化)
#include<cstdio>
#include<string>
#include<cmath>
#include<memory.h>
using namespace std;
int x[101],y[101];
int n=0,ma;
int cj(int i,int j,int k)(那啥,叉积)
{
return (x[i]-x[k])*(y[j]-y[k])-(x[j]-x[k])*(y[i]-y[k]);
}
int main()
{
scanf("%d",&n);
for (int i=1;i<=n;i++)
scanf("%d%d",&x[i],&y[i]);
for (int i=1;i<=n-2;i++)
{
for (int j=i+1;j<=n-1;j++)
{
int ans=2;
for (int k=j+1;k<=n;k++)
if (cj(i,j,k)==0) ans++;
ma=max(ma,ans);
}
if (ma>n-i+1) break;//小优化,几乎没啥用。
}
printf("%d",ma);
}