Pagini recente » Cod sursa (job #2435174) | Cod sursa (job #1050233) | Cod sursa (job #1254364) | Cod sursa (job #650078) | Cod sursa (job #1996152)
#include <fstream>
#include <iostream>
#include <unordered_map>
using namespace std;
ifstream f("trapez.in");
ofstream g("trapez.out");
const int nmax = 1005;
int n, i, j, x, y;
double pnt;
struct punct {
int x, y;
}v[1005];
long long sol;
unordered_map <long double, int> cnt2;
unordered_map <double, int> cnt;
long double p;
int main() {
f >> n;
for (i = 1; i <= n; i++) {
f >> x >> y;
v[i] = {x,y};
}
for (i = 1; i <= n; i++) {
for (j = i+1; j <= n; j++) {
if (v[j].x == v[i].x) {
if (v[j].y > v[i].y)
pnt = -2e9-5;
else pnt = -2e9-6;
}
else pnt = (double)(v[j].y-v[i].y)/(v[j].x-v[i].x);
cnt[pnt]++;
p = i*4.01e9+pnt+2e9+10;
cnt2[p]++;
}
}
for (i = 1; i <= n; i++) {
for (j = i+1; j <= n; j++) {
if (v[j].x == v[i].x) {
if (v[j].y > v[i].y)
pnt = -2e9+5;
else pnt = -2e9+6;
}
else pnt = (double)(v[j].y-v[i].y)/(v[j].x-v[i].x);
p = i*4.01e9+pnt+2e9+10;
y = cnt2[p];
x = cnt[pnt]-y;
if (y) sol += (x*y);
cnt2[p] = 0;
}
}
g << sol/2;
return 0;
}