Pagini recente » Cod sursa (job #1719996) | Autentificare | Cod sursa (job #507918) | Cod sursa (job #2289098) | Cod sursa (job #2842002)
#include <bits/stdc++.h>
using namespace std;
const int NMAX = 1000;
struct fractie {
int a, b; // a / b
};
fractie v[NMAX * NMAX];
bool cmp(fractie x, fractie y) {
return (1LL * x.a * y.b <= 1LL * x.b * y.a);
}
bool isEqual(fractie x, fractie y) {
return (1LL * x.a * y.b == 1LL * x.b * y.a);
}
int coordX[NMAX], coordY[NMAX];
int main() {
int n, i, j, pantaInf, trapez, pante, nr;
FILE *fin, *fout;
fin = fopen("trapez.in", "r");
fscanf(fin, "%d", &n);
for(i = 0; i < n; i++)
fscanf(fin, "%d%d", &coordX[i], &coordY[i]);
fclose(fin);
pantaInf = 0;
pante = 0;
for(i = 0; i < n; i++) {
for(j = i + 1; j < n; j++) {
if(coordX[i] == coordX[j]) {
pantaInf++;
} else {
v[pante].a = coordY[j] - coordY[i];
v[pante].b = coordX[j] - coordX[i];
pante++;
}
}
}
sort(v, v + pante, cmp);
//cout << "pantaInf = " << pantaInf << endl;
trapez = pantaInf * (pantaInf - 1) / 2;
i = 0;
while(i < pante) {
nr = 1;
while(i < pante - 1 && isEqual(v[i], v[i + 1])) {
nr++;
i++;
}
//cout << "nr = " << nr << endl;
trapez += nr * (nr - 1) / 2;
i++;
}
fout = fopen("trapez.out", "w");
fprintf(fout, "%d", trapez);
fclose(fout);
return 0;
}