Cod sursa(job #1981596)

Utilizator MarutBrabete Marius Stelian Marut Data 16 mai 2017 10:32:52
Problema Trapez Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.1 kb
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;
struct point
{
    int x,y;
};
point temp;
vector<point>v;
vector<double>p;
const double eps=1.e-14;
const double INF=2.e9;
vector<int>::iterator it;
bool vertical(point A, point B)
{
    return A.x==B.x;
}
double panta(point A, point B)
{
    if(vertical(A,B)) return INF;
    return (1.0*(B.y-A.y)/(B.x-A.x));
}
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int j,n,i,x2,x1;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d%d",&x2,&x1);
        temp.x=x2;
        temp.y=x1;
        v.push_back(temp);
    }
    for(i=0;i<n-1;i++)
        for(j=i+1;j<=n-1;j++)
            p.push_back(panta(v[i],v[j]));
    sort(p.begin(),p.end());
    int k,l,lmax;
    lmax=0;
    l=1;
    k=p.size();
    for(i=0;i<k;i++)
    {
        if(fabs(p[i]-p[i+1])<eps) l++;
            else
            {
                if(l>lmax) lmax=l;
                l=1;
            }
    }
    printf("%d",lmax*(lmax-1)/2);
    return 0;
}