poj2780

同2606

View Code
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;

#define eps 1.0e-8
#define maxn 1005

struct XPoint
{
int x, y;
} point[maxn];

struct Line
{
int a, b;
double k;
bool end;
} line[maxn * maxn];

int n, ncount;

bool operator <(const Line &a, const Line &b)
{
if (abs(a.k - b.k) > eps && !a.end && !b.end)
return a.k < b.k;
if (a.end != b.end)
return a.end < b.end;
if (a.a != b.a)
return a.a < b.a;
return a.b < b.b;
}

double getk(XPoint &a, XPoint &b)
{
return (b.y - a.y) * 1.0 / (b.x - a.x);
}

int main()
{
//freopen("t.txt", "r", stdin);
while (~scanf("%d", &n))
{
ncount = 0;
for (int i = 0; i < n; i++)
scanf("%d%d", &point[i].x, &point[i].y);
for (int i = 0; i < n - 1; i++)
for (int j = i + 1; j < n; j++)
{
line[ncount].a = i;
line[ncount].b = j;
if (point[i].x == point[j].x)
line[ncount].end = true;
else
{
line[ncount].end = false;
line[ncount].k = getk(point[i], point[j]);
}
ncount++;
}
sort(line, line + ncount);
int start = 0;
int ans = 0;
for (int i = 1; i < ncount; i++)
{
if (!((line[i].end && line[start].end) || ((!line[i].end && !line[start].end) && (line[i].k - line[start].k) < eps)) || line[i].a != line[start].a)
{
start = i;
continue;
}
if (i - start > ans)
{
ans = i - start;
}
}
printf("%d\n", ans + 2);
}
return 0;
}

原文地址:https://www.cnblogs.com/rainydays/p/2199773.html