Pagini recente » Cod sursa (job #3155120) | Cod sursa (job #1812337) | Cod sursa (job #809258) | Cod sursa (job #653627) | Cod sursa (job #2660601)
#include<iostream>
#include<vector>
#include<algorithm>
#include<fstream>
#define infinit 9000000000
using namespace std;
typedef long long ll;
typedef pair<ll, ll> punct;
ifstream f("trapez.in");
ofstream g("trapez.out");
int N;
vector<punct> puncte;
vector<double> pante;
int rezultat;
void citire()
{
f >> N;
for (int i = 1; i <= N; i++)
{
int x, y;
f >> x >> y;
puncte.push_back(make_pair(x, y));
}
for (int i = 0; i <= N-1; i++)
cout << puncte[i].first << " " << puncte[i].second << endl;
}
double make_panta(punct a, punct b)
{
if (a.first == b.first)
return infinit ;
else
return (a.second - b.second)/ (double)(a.first - b.first);
}
void rezolvare()
{
int contor = 1;
for (size_t i = 0; i < N - 1; i++)
for (size_t j = i + 1; j < N; j++)
pante.push_back(make_panta(puncte[i], puncte[j]));
//cout << puncte[i].first << " " << puncte[i].second << " + " << puncte[j].first << " " << puncte[j].second << endl;
sort(pante.begin(), pante.end(), [](double a, double b) {return a < b; });
for (size_t i = 1; i < pante.size(); i++)
if (pante[i] == pante[i - 1])
contor++;
else
{
rezultat += contor * (contor - 1) / 2;
contor = 1;
}
g << rezultat;
}
int main()
{
citire();
rezolvare();
return 0;
}