Cod sursa(job #1981594)

Utilizator Alex_AeleneiAlex Aelenei Ioan Alex_Aelenei Data 16 mai 2017 10:30:42
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.12 kb
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
using namespace std;
struct POINT
{
    int x,y;
};
vector <POINT> v;
vector <double> pante;
const double eps=1.e-14;
const double INF=2.e9;
bool vertical(POINT A,POINT B)
{
    if(A.x==B.x)
        return 1;
    else 
        return 0;
}
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 n,a,b,i,j;
    POINT temp;
    scanf("%d",&n);
    for(i=1;i<=n;++i)
    {
        scanf("%d%d",&a,&b);
        temp.x=a;temp.y=b;
        v.push_back(temp);
    }
    for(i=0;i<n-1;++i)
        for(j=i+1;j<n;++j)
            pante.push_back(panta(v[i],v[j]));
    sort(pante.begin(),pante.end());
    int k=pante.size(),l=0,s=0;
    for(i=0;i<pante.size()-1;i++)
    {
        if(pante[i+1]==pante[i])
            l++;
        else
        {
            if(l!=0)
                s=s+l*(l+1)/2;
            l=0;
        }
    }
    printf("%d",s);
    return 0;
}