Cod sursa(job #2625171)

Utilizator iuliangal186Gal Iulian iuliangal186 Data 5 iunie 2020 19:32:14
Problema Trapez Scor 10
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 0.91 kb
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
using namespace std;

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

struct coord{
    long long x, y;
}v[1005];

vector<long double> panta;
int n;
int trapez()
{
    long double p;
    int sol = 0, k = 1;
    for(int i = 1; i <= n; ++i)
        for(int j = i + 1; j <= n; ++j)
        {
            if(v[i].x != v[j].x)
                p = (v[j].y - v[i].y)*1.0 / (v[j].x - v[i].x);
            panta.push_back(p);
        }

    sort(panta.begin(), panta.end());

    for(int i = 1; i < panta.size(); ++i)
        if(panta[i] == panta[i - 1])
            k++;
        else{
            sol += k * (k - 1) / 2;
            k = 1;
        }
    return k;
}
int main()
{
    fin >> n;
    for(int i = 1; i <= n; ++i)
    {
        fin>>v[i].x>>v[i].y;
    }
    fout << trapez();
    return 0;
}