Cod sursa(job #1771747)

Utilizator stelian2000Stelian Chichirim stelian2000 Data 5 octombrie 2016 22:38:07
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.75 kb
#include <cstdio>
#include <algorithm>

using namespace std;

struct punct
{
    int x,y;
};

punct v[1010];
double v1[1000010];

int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,l=0,s,r=0;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&v[i].x,&v[i].y);
    for(int i=1;i<=n;i++)
        for(int j=i+1;j<=n;j++)
        {
            l++;
            v1[l]=1.0*(v[i].y-v[j].y)/(v[i].x-v[j].x);
        }
    sort(v1+1,v1+l+1);
    s=1;
    for(int i=1;i<=l-1;i++)
        if(v1[i]==v1[i+1]) s++;
        else
        {
            r=r+(s-1)*s/2;
            s=1;
        }
    if(v1[l-1]==v1[l]) s++;
    r=r+(s-1)*s/2;
    printf("%d",r);
    return 0;
}