POJ 3668 Game of Lines

POJ_3668

    可以先将所有的直线求出来,然后按斜率排个序,之后顺序扫描一遍就可以统计出结果了。

#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAXD 210
struct Point
{
    int x, y;
    bool operator < (const Point &t) const
    {
        if(x == t.x) return y < t.y;
        return x < t.x;
    }
}p[MAXD];
struct Vector
{
    int x, y;
    bool operator < (const Vector &t) const
    {
        return y * t.x < x * t.y;
    }
    bool operator != (const Vector &t) const
    {
        return y * t.x != x * t.y;
    }
}a[MAXD * MAXD];
int N;
void init()
{
    int i;
    for(i = 0; i < N; i ++) scanf("%d%d", &p[i].x, &p[i].y);
}
void solve()
{
    int i, j, n = 0, cnt;
    std::sort(p, p + N);
    for(i = 0; i < N; i ++)
        for(j = i + 1; j < N; j ++)
            a[n].x = p[j].x - p[i].x, a[n].y = p[j].y - p[i].y, ++ n;
    std::sort(a, a + n);
    for(i = cnt = 1; i < n; i ++)
        if(a[i] != a[i - 1]) ++ cnt;
    printf("%d\n", cnt);
}
int main()
{
    while(scanf("%d", &N) == 1)
    {
        init();
        solve();
    }
    return 0;
}
原文地址:https://www.cnblogs.com/staginner/p/2706437.html