2005-2006 ACM-ICPC East Central North America Regional Contest (ECNA 2005) G.Swamp Things

来源:互联网 发布:广志工资知乎 编辑:程序博客网 时间:2024/05/21 07:00

这里写图片描述

这里写图片描述

分析:
给你N个点,让你找到一条直线,这条直线所经过的点最多,求出共线的点最多有多少个,少于4个就当成没有。

#include <iostream>#include <sstream>#include <iomanip>#include <vector>#include <deque>#include <list>#include <set>#include <map>#include <stack>#include <queue>#include <bitset>#include <string>#include <numeric>#include <algorithm>#include <functional>#include <iterator>#include <cstdio>#include <cstring>#include <cmath>#include <cstdlib>#include <cctype>#include <complex>#include <ctime>#define INF 0x3f3f3f3f#define eps 1e-10typedef long long LL;const double pi = acos(-1.0);const long long mod = 1e9 + 7;using namespace std;double a[1005];typedef struct{    int x,y;}Point;Point Point1[1005];int main(){    //freopen("int.txt","r",stdin);    //freopen("out.txt","w",stdout);    int N;    int t = 1;    while(scanf("%d",&N) && N)    {        for(int i = 1;i <= N;i++)            scanf("%d %d",&Point1[i].x,&Point1[i].y);        int ans = 0;        for(int i = 1;i <= N;i++)        {            int k = 0;            for(int j = i + 1;j <= N;j++)            {                if(Point1[i].x == Point1[j].x)                    a[k++] = INF;                else                    a[k++] = ( Point1[i].y - Point1[j].y) * 1.0 / (Point1[i].x - Point1[j].x);            }            sort(a,a + k);            for(int j = 0;j < k;j++)            {                int cas = 1;                while(j < k - 1&& fabs(a[j] - a[j + 1]) < eps)                {                    j++;                    cas++;                }                ans = max(ans,cas);            }        }        ans++;        if(ans < 4)            ans = 0;        printf("Photo %d: %d points eliminated\n",t++,ans);    }    return 0;}
0 0