Cod sursa(job #1178732)

Utilizator xtreme77Patrick Sava xtreme77 Data 27 aprilie 2014 01:31:40
Problema Trapez Scor 50
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.61 kb
#include <cstdio>
#include <map>
#define MAX 1111
using namespace std;
struct coord{
    int x,y;
}q[MAX];int s,n,x;
map<double, int> hashin;
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;++i)scanf("%d%d",&q[i].x,&q[i].y);
    for(int i=1;i<n;++i)
        for(int j=i+1;j<=n;++j)
            hashin[(float)(q[j].y-q[i].y)/(q[j].x-q[i].x)]++;
    map<double, int>::iterator it;
    for(it=hashin.begin(); it!=hashin.end(); ++it){
        x=it->second;
        s+=x*(x-1)/2;
    }
    printf("%d\n",s);
    return 0;
}