Cod sursa(job #1122722)

Utilizator sebinechitasebi nechita sebinechita Data 25 februarie 2014 20:06:44
Problema Trapez Scor 40
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.77 kb
#include <iostream>
#include <fstream>
#include <map>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
#define MAX 1100
map < float , int > harta;

pair<int, int> a[MAX];

int main()
{
    int n, i, j, x, y, l=0;
    fin>>n;
    for(i=1;i<=n;i++)
    {
        fin>>a[i].first>>a[i].second;
    }
    for(i=1;i<=n;i++)
    {
        for(j=i+1;j<=n;j++)
        {
            x=a[i].first-a[j].first;
            y=a[i].second-a[j].second;
            if(x==0)
                l++;
            else
                harta[(float)y/x]++;
        }
    }
    int s=l*(l-1)/2;

    for(map<float, int>::iterator it=harta.begin();it!=harta.end();it++)
    {
        l=(*it).second;
        s+=(l*(l-1)/2);
    }
    fout<<s;

}