Pagini recente » Cod sursa (job #988963) | Cod sursa (job #2629020)
#include <bits/stdc++.h>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
const int nmax = 1000;
int n, z;
long long ans = 0;
struct Point
{
int x, y;
}v[nmax + 5];
struct Segment
{
Point a, b;
}s[nmax * nmax + 5];
bool cmp(Segment s1, Segment s2)
{
return 1LL * (s1.b.y - s1.a.y) * (s2.b.x - s2.a.x) <= 1LL * (s2.b.y - s2.a.y) * (s1.b.x - s1.a.x);
}
bool egal(Segment s1, Segment s2)
{
return 1LL * (s1.b.y - s1.a.y) * (s2.b.x - s2.a.x) == 1LL * (s2.b.y - s2.a.y) * (s1.b.x - s1.a.x);
}
int main()
{
fin >> n;
for (int i = 1; i <= n; ++i)
{
fin >> v[i].x >> v[i].y;
for (int j = i - 1; j >= 1; --j)
{
s[++z] = {v[i], v[j]};
}
}
sort(s + 1, s + z + 1, cmp);
for (int i = 1; i <= z; ++i)
{
int j = i + 1;
while (egal(s[i], s[j]) && j <= z) ++j;
--j;
int contor = j - i + 1;
ans = 1LL * ans + 1LL * contor * (contor - 1) / 2;
i = j;
}
fout << ans;
fin.close();
fout.close();
return 0;
}