Pagini recente » Cod sursa (job #3271239) | Cod sursa (job #1192243) | Cod sursa (job #1988845) | Cod sursa (job #2121896) | Cod sursa (job #611138)
Cod sursa(job #611138)
#include <stdio.h>
#include <math.h>
#include <algorithm>
#define eps 1.e-18
#define INF 1.e20
#define eq2(x, y) (fabs((x)-(y))<eps)
#define eq(x, y) ((x)-(y)==0)
using namespace std;
class POINT {
public:
double x, y;
void read(char type = 'i') {//i = long, d = double
long ax, ay;
double bx, by;
if(type == 'i') {
scanf("%ld%ld", &ax, &ay);
x = ax;
y = ay;
}
else {
scanf("%lf%lf", &bx, &by);
x = bx;
y = by;
}
}
double panta(POINT &other) {
if(eq(other.x, x))
return INF;
else return (other.y - y) / (other.x - x);
}
};
class double_ {public:
double x;
};
long n, nm;
double pante[500000];
double p, lp;
POINT P[1001];
int cmp(double x, double y) {
if(x-y >=eps)
return 0;
else return 1;
}
int main() {
long i, j, i1, k = 0, d, cs;
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
scanf("%ld", &n);
for(i = 1; i <= n; i++)
P[i].read('i');
for(i = 1; i < n; i++)
for(j = i + 1; j <= n; j++) {
p = P[i].panta(P[j]);
pante[++nm] = p;
}
sort(&pante[1], &pante[nm + 1], cmp);
//sort(&pante[1], &pante[nm + 1]);
i=1;
cs = 1;
lp = pante[i];
for(i = 2; i <= nm + 1; i++) {
if(eq2(lp, pante[i]))
cs++;
else {
lp = pante[i];
k += (cs * (cs - 1)) / 2;
cs = 1;
}
}
printf("%ld", k);
return 0;
}