poj 1118 Lining Up

#include<iostream>
using namespace std;

double c[702][2];//坐标数组
double k[702];//斜率数组

int cmp( const void* a , const void* b )
{
return *(double *)a > *(double *)b ? 1 : -1;
}
int main()
{
int n,cnt,max,num;
while(cin >> n)
{
if(n == 0)break;
for(int i = 1;i <= n; ++i)
cin
>> c[i][0] >> c[i][1];
max
= 2;
for(int i = 1;i <= n; ++i)
{
cnt
= 0;
num
= 2;//最少有2个点满足条件
for(int j = i+1;j <= n;++j)
{
if(c[i][0] - c[j][0] != 0)
k[cnt
++] = (c[i][1] - c[j][1])/(c[i][0] - c[j][0]);
else
k[cnt
++] = 2147483647; //若斜率不存在,则用最大值代替
}
qsort(k,cnt,
sizeof(k[0]),cmp); //先将斜率数组排序,方便对共线点数的判定
for(int i = 0;i < cnt-1;++i)
if(k[i] == k[i+1])
{
++num;
if(num > max)
max
= num;
}
else
num
= 2;
}
cout
<< max <<endl;
}
return 0;
}

  

posted on 2011-07-17 23:47  sysu_mjc  阅读(143)  评论(0编辑  收藏  举报

导航