Cod sursa(job #1018830)

Utilizator dan.ghitaDan Ghita dan.ghita Data 29 octombrie 2013 23:44:10
Problema Trapez Scor 90
Compilator cpp Status done
Runda Arhiva de probleme Marime 0.59 kb
#include<iostream>
#include<fstream>
#include<cmath>
#include<algorithm>
#include<unordered_map>
using namespace std;
int n, s;
double x;
struct punct{
int a, b;
} v[1002];
unordered_map<double, int> m;

int main()
{
ifstream f("trapez.in");
ofstream g("trapez.out");

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;
}
s+=x*(x-1)/2;
g<<s<<'\n';
g.close();
}