Pagini recente » Cod sursa (job #1604120) | Cod sursa (job #2733615) | Cod sursa (job #1671629) | Cod sursa (job #301774) | Cod sursa (job #2916320)
#include <fstream>
#include <algorithm>
using namespace std;
#define N 1000
#define NM 499500
typedef unsigned long long ull;
ifstream f("trapez.in");
ofstream g("trapez.out");
struct point {
int x, y;
bool operator == (const point& a) const {
return x == a.x && y == a.y;
}
};
point v[N], m[NM];
// a.y b.y
// --- < ---
// a.x b.x
bool cmp(point a, point b) {
return (ull)a.y * b.x < (ull)a.x * b.y;
}
// gcd cannot be 0
point slope(point a, point b) {
int dy = b.y - a.y;
int dx = b.x - a.x;
int gcd = __gcd(dx, dy);
return {dx / gcd, dy / gcd};
}
int main() {
int n, idx = 0;
f >> n;
for (int i = 0; i < n; i++) {
f >> v[i].x >> v[i].y;
for (int j = 0; j < i; j++)
m[idx++] = slope(v[i], v[j]);
}
sort(m, m + idx, cmp);
int s = 0, cnt = 1;
for (int i = 0 ; i < idx; i++)
if (m[i] == m[i + 1])
cnt++;
else {
s += cnt * (cnt - 1);
cnt = 1;
}
g << (s >> 1);
return 0;
}