Pagini recente » Cod sursa (job #2639950) | Cod sursa (job #2232260) | Cod sursa (job #2680480) | Cod sursa (job #186269) | Cod sursa (job #76107)
Cod sursa(job #76107)
#include <cstdio>
#include <algorithm>
#include <cmath>
const int maxn = 1000;
const double eps = 0.000000000000001;
const double inf = 2000000002.0;
FILE *in = fopen("trapez.in","r"), *out = fopen("trapez.out","w");
struct punct
{
int x, y;
};
int n;
punct a[maxn];
int k;
struct dbl
{
double p;
};
dbl p[maxn*maxn];
void read()
{
fscanf(in, "%d", &n);
for ( int i = 0; i < n; ++i )
fscanf(in, "%d %d", &a[i].x, &a[i].y);
}
void go()
{
for ( int i = 0; i < n; ++i )
for ( int j = i + 1; j < n; ++j )
{
if ( a[i].x == a[j].x )
p[k++].p = inf;
else
p[k++].p = (double)( a[i].y - a[j].y ) / ( a[i].x - a[j].x );
}
}
bool operator<(const dbl &x, const dbl &y)
{
return x.p - y.p < -eps;
}
int main()
{
read();
go();
std::sort(p, p+k);
int cnt = 1;
int r = 0;
for ( int i = 1; i < k; ++i )
{
if ( p[i].p - p[i-1].p < eps )
++cnt;
else
r += (cnt*(cnt-1))/2, cnt = 1;
}
fprintf(out, "%d\n", r);
return 0;
}