Pagini recente » Cod sursa (job #2791132) | Cod sursa (job #2886068) | Cod sursa (job #2986631) | Cod sursa (job #97327) | Cod sursa (job #2876273)
#include <fstream>
#include <map>
#include <algorithm>
#define nmax 1000
#define inf 1000000
using namespace std;
struct pct
{
int x, y;
};
bool cmp (pct a, pct b)
{
if (a.x == b.x)
return a.y < b.y;
return a.x < b.x;
}
struct panta
{
int numa, numi;
bool operator< (const panta& a)const
{
if (numa == a.numa)
return numi < a.numi;
return numa < a.numa;
}
};
panta pantify (pct a, pct b)
{
if (b.x - a.x == 0)
return {inf, inf};
int gcd = __gcd (b.y - a.y, b.x - a.x);
panta x = { (b.y - a.y) / gcd, (b.x - a.x) / gcd};
if (x.numa < 0 && x.numi < 0)
x.numa *= -1, x.numi *= -1;
else if (x.numi < 0)
x.numa *= -1, x.numi *= -1;
return x;
}
const double eps = 1e-6, cons = 1.0000000;
pct v[nmax + 1];
map<panta, int> f;
map<panta, int>::iterator it;
int main()
{
ifstream cin ("trapez.in");
ofstream cout ("trapez.out");
int n, i, j;
long long tot = 0;
cin >> n;
for (i = 1; i <= n; i++)
cin >> v[i].x >> v[i].y;
sort (v + 1, v + n + 1, cmp);
for (i = 1; i <= n; i++)
for (j = i + 1; j <= n; j++)
f[pantify (v[i], v[j])]++;
for (it = f.begin(); it != f.end(); it++)
tot += (it->second) * (it->second - 1) / 2;
cout << tot;
return 0;
}