poj 2606 Rabbit hunt
#include<iostream> //参照poj 1118 Lining Up
using namespace std;
double c[201][2];//坐标数组
double k[201];//斜率数组
//QSORT的double类型比较函数
int cmp_double( const void* a , const void* b )
{
return *(double *)a > *(double *)b ? 1 : -1;
}
int main()
{
int n,cnt,max,num;
cin>>n;
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; //若斜率不存在,则用int的最大值代替
}
qsort(k,cnt,sizeof(k[0]),cmp_double);//先将斜率数组排序,方便对共线点数的判定
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;
}