• 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;
    }

  • 相关阅读:
    一些技术鸡汤
    css优化
    Spring 通过maven pom文件配置初始化
    sql 编写横竖表转换
    Linux 常用命令笔记 (持续更新)
    java常用集合详解 contains
    jQuery Ajax(异步请求)
    java中"与"和"或"
    java8 中的时间和数据的变化
    mysql 根据查询结果集更新
  • 原文地址:https://www.cnblogs.com/rainydays/p/2199773.html
Copyright © 2020-2023  润新知