Cod sursa(job #1332542)

Utilizator wGEORGEWGeorge Cioti wGEORGEW Data 2 februarie 2015 10:10:32
Problema Trapez Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.98 kb
#include<stdio.h>
#include<algorithm>
using namespace std;
int sol,l,nr,i,n;
struct punct 
{
    int x, y;
};
punct a[1004];
 
struct str
{
    int s,j;
    str(int ss=0,int jj=0)
    {
        s=ss;
        j=jj;
 
    }
};
str v[1000*1000+4];
bool sortare(str a, str b)
{
    return (long long ) a.s*b.j>(long long )a.j*b.s;
}
int main()
{
    int j;
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&n);
    for(i=1;i<=n;i++)
        scanf("%d%d",&a[i].x,&a[i].y);
    for(i=1;i<=n;i++)
        for(j=i+1;j<=n;j++)
        {
            nr++;
            v[nr]=str(a[i].x-a[j].x,a[i].y-a[j].y);
        }   
    sort(v+1,v+1+nr,sortare);
    l=1;
    for(int i=2;i<=nr;i++)
    {
        if(v[i].s*v[i-1].j==v[i].j*v[i-1].s){
            l++;
        }
        else{
             
            sol+=l*(l-1)/2;
            l=1;
        }
 
    }
    sol+=l*(l-1)/2;
    printf("%d",sol);
    return 0;
 
 
}