Pagini recente » Cod sursa (job #1795549) | Cod sursa (job #675825) | Cod sursa (job #320664) | Cod sursa (job #1545847) | Cod sursa (job #1033883)
#include <fstream>
#include <algorithm>
using namespace std;
ifstream fin("trapez.in");
ofstream fout("trapez.out");
#define x first
#define y second
#define NMAX 1001
#define PII pair <int, int>
int i, j, N, nr;
int cnt;
int ANS;
PII P[NMAX];
PII Pante[NMAX * NMAX];
struct cmp {
bool operator() (const PII &a, const PII &b) const {
if (a.x * b.y == b.x * a.y) return 1;
else
if (a.x * b.y < b.x * a.y) return 1;
return 0;
};
};
int main() {
fin >> N;
for (i = 1; i <= N; ++i)
fin >> P[i].x >> P[i].y;
for (i = 1; i <= N; ++i) {
for (j = i + 1; j <= N; ++j) {
Pante[++cnt].x = P[j].x - P[i].x;
Pante[cnt].y = P[j].y - P[i].y;
}
}
sort(Pante + 1, Pante + cnt + 1, cmp());
for (i = 2; i <= cnt; ++i) {
nr = 0;
while (Pante[i].x * Pante[i - 1].y == Pante[i].y * Pante[i - 1].x) ++nr, ++i;
ANS += (nr * (nr - 1) / 2);
if (nr == 1) ++ANS;
}
fout << ANS << '\n';
return 0;
}