Cod sursa(job #1018847)

Utilizator dan.ghitaDan Ghita dan.ghita Data 30 octombrie 2013 00:17:38
Problema Trapez Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.58 kb
#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<unordered_map>
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
int n, s;
double x;
struct punct{
int a, b;
} v[1002];
unordered_map<double, int> m;

int main()
{

f>>n;
for(int i=0;i<n;i++)
    f>>v[i].a>>v[i].b;

for(int i=0;i<n-1;i++)
for(int j=i+1;j<n;j++)
    m[(float)(v[j].b-v[i].b)/(v[j].a-v[i].a)]++;

unordered_map<double, int>::iterator mt;
for(mt=m.begin(); mt!=m.end(); ++mt)
{
    x=mt->second;
    s+=x*(x-1)/2;
}
g<<s<<'\n';
g.close();
}