Pagini recente » Borderou de evaluare (job #2021618) | Borderou de evaluare (job #1796617) | Borderou de evaluare (job #1354994) | Borderou de evaluare (job #2627967) | Cod sursa (job #2916318)
#include <fstream>
#include <algorithm>
using namespace std;
#define N 1000
#define NM 499500
typedef long long ll;
ifstream f("trapez.in");
ofstream g("trapez.out");
struct point {
ll x, y;
bool operator == (const point& a) const {
return x * a.y == a.x * y;
}
};
point v[N], m[NM];
// a.x b.x
// --- < ---
// a.y b.y
bool cmp(point a, point b) {
return a.x * b.y < a.y * b.x;
}
point slope(point a, point b) {
return {b.x - a.x, b.y - a.y};
}
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;
}