Cod sursa(job #2619144)

Utilizator georgeblanarBlanar George georgeblanar Data 27 mai 2020 09:22:26
Problema Trapez Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.96 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <limits>
#include <map>

#define N 1000
std:: ifstream f;
std::ofstream g;
struct coord{
    float x, y;
};

int main()
{
    int n;
    coord vect[N];
    std::map<float, int> xd;
    long trapeze = 0;

    f.open("trapez.in");
    f >> n;
    for (int i = 0; i < n; i++) {
        f >> vect[i].x;
        f >> vect[i].y;
    }

    for (int i = 0; i < n; i++) {
    }
    f.close();
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            if (vect[i].x == vect[j].x) {
                xd[std::numeric_limits<float>::infinity()] ++;
            }
            else {
                xd[(vect[j].y - vect[i].y) / (vect[j].x - vect[i].x)]++;
            }
        }
    }
    for (auto it = xd.begin(); it != xd.end(); it++) {
        trapeze += ((*it).second * ((*it).second - 1)) / 2;
    }
    g.open("trapez.out");
    g << trapeze;
}