Cod sursa(job #1185483)

Utilizator apopeid15Apopei Daniel apopeid15 Data 15 mai 2014 20:24:08
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.72 kb
#include <cstdio>
#include <unordered_map>
#define MAX 1005
 
using namespace std;
 
unordered_map <double,int> h;
 
struct puncte{
    int x,y;
};puncte v[MAX];
 
int main()
{
    freopen("trapez.in","r",stdin);
    freopen("trapez.out","w",stdout);
    int n,a,b;
    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++){
            a=v[i].x-v[j].x;
            b=v[i].y-v[j].y;
            ++h[(double)b/a];
 
        }
    int sol=0;
    unordered_map<double, int>::iterator it;
    for(it=h.begin();it!=h.end();it++){
        a=it->second;
        sol+=a*(a-1)/2;
    }
    printf("%d",sol);
    return 0;
}