Cod sursa(job #2620198)

Utilizator AokijiAlex M Aokiji Data 28 mai 2020 16:20:59
Problema Trapez Scor 40
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.1 kb
#include <iostream>
#include <fstream>
#include <vector>

#define INF 9999999

using namespace std;

ifstream fin("trapez.in");
ofstream fout("trapez.out");

struct point{
    int x, y;
};
struct slopes{
    float m;
    int count, nt;
};

float calculate_slope(point a, point b){
    if(a.x==b.x) return INF;
    return ((float)(a.y-b.y))/((float)(a.x-b.x));
}

int main() {
    int n;
    float m;
    point c;
    vector<point> a;
    vector<slopes> s;
    fin>>n;
    for(int i=0;i<n;i++){
        fin>>c.x>>c.y;
        if(i>0)
            for(auto ai : a){
                bool found = false;
                m = calculate_slope(ai, c);
                for(int j=0;j<s.size();j++)
                    if(s[j].m==m){
                        s[j].nt+=s[j].count;
                        s[j].count++;
                        found = true;
                    }
                if(!found) s.push_back({m, 1, 0});
            }
        a.push_back(c);
    }
    int rez = 0;
    for(auto si : s)
        if(si.count>1)
            rez+=si.nt;
    fout<<rez;
    return 0;
}