Cod sursa(job #2297636)

Utilizator moise_alexandruMoise Alexandru moise_alexandru Data 6 decembrie 2018 10:04:31
Problema Trapez Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.87 kb
#include <algorithm>
#include <iostream>
#include <fstream>
#include <vector>
using namespace std;
ifstream in("trapez.in");
ofstream out("trapez.out");
#define int long long
const int maxn = 1005;
pair <int, int> pct[maxn];
vector <pair <int, int> > v;

inline int mod(int x)
{
    if(x < 0)
        return -x;
    return x;
}

inline bool cmp(pair <int, int> x, pair <int, int> y)
{
    if(x.second == 0 || y.second == 0)
    {
        if(x.second != y.second)
            return (x.second == 0);
        return x.first < y.first;
    }
    double aux1 = x.first / x.second;
    double aux2 = y.first / y.second;
    if(aux1 != aux2)
        return aux1 < aux2;
    return x.first < y.first;
}

inline bool egale(pair <int, int> a, pair <int, int> b)
{
    if(a.second == 0 || b.second == 0)
    {
        if(a.second != b.second)
            return 0;
        return 1;
    }
    double aux1 = (double)a.first / a.second;
    double aux2 = (double)b.first / b.second;
    return (aux1 == aux2);
}

int32_t main()
{
    //cerr << "intra";
    int n;
    in >> n;
    for(int i = 1; i <= n; i++)
        in >> pct[i].first >> pct[i].second;
    //cerr << "intra";
    for(int i = 1; i <= n; i++)
        for(int j = i + 1; j <= n; j++)
            v.push_back(make_pair(pct[i].first - pct[j].first, pct[i].second - pct[j].second));
    //cerr << "intra" << "\n";
    sort(v.begin(), v.end(), cmp);
    //cerr << "iese" << "\n";
    int nr = 0;
    for(unsigned int i = 1; i < v.size(); i++)
    {
        if(egale(v[i], v[i - 1]))
        {
            nr++;
            //cerr << i << " " << v[i].first << " " << v[i].second << " : " << v[i - 1].first << " " << v[i - 1].second << "\n";
        }
    }
    out << nr << "\n";
    /*
    for(auto it : v)
        cerr << it.first << " " << it.second << "\n";
    */
    return 0;
}