Cod sursa(job #2743618)

Utilizator TeodoraMaria123Serban Teodora Maria TeodoraMaria123 Data 23 aprilie 2021 12:46:46
Problema Trapez Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.95 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
const int inf=1e9;
const int nmax=5e5;
struct point
{
    int x,y;
};
bool cmp(point p1,point p2)
{
    if(p1.x==p2.x)
        return p1.y<p2.y;
    return p1.x<p2.x;
}
point v[nmax],p[1010];
int main()
{
    int n,i,j,a,b,g,k=0,c,rez=0;
    in>>n;
    for(i=1; i<=n; i++)
        in>>p[i].x>>p[i].y;
    for(i=1; i<n; i++)
        for(j=i+1; j<=n; j++)
        {
            a=p[i].x-p[j].x;
            b=p[i].y-p[j].y;
            g=__gcd(a,b);
            a/=g;
            b/=g;
            v[++k].x=a;
            v[k].y=b;
        }
    sort(v+1,v+k+1,cmp);
    i=2;
    while(i<=k)
    {
        c=1;
        while(i<=k  &&  v[i].x==v[i-1].x  &&  v[i].y==v[i-1].y)
            c++,i++;
        if(c>1)
            rez+=c*(c-1)/2;
        i++;
    }
    out<<rez;
    return 0;
}