Pagini recente » Cod sursa (job #1405759) | Cod sursa (job #3248588) | Cod sursa (job #34939) | Cod sursa (job #1000947) | Cod sursa (job #1005441)
#include <cstdio>
#include <algorithm>
#define N 1001
#define INF (1<<30)
using namespace std;
struct pc
{
double x, y;
};
struct segm
{
pc a, b;
double p;
bool operator <(const segm &e) const
{
return p<e.p;
}
};
pc a[N];
segm b[N*N];
int main()
{
freopen("trapez.in", "r", stdin);
freopen("trapez.out", "w", stdout);
int n, m=0, i, j, s=0, sol=0;
scanf("%d ", &n);
for(i=1;i<=n;i++)
{
scanf("%lf %lf ", &a[i].x, &a[i].y);
for(j=1;j<i;j++)
{
m++;
b[m].a=a[i];
b[m].b=a[j];
if(b[m].a.x==b[m].b.x)
{
b[m].p=INF;
}
else
{
b[m].p=(b[m].a.y-b[m].b.y)/(b[m].a.x-b[m].b.x);
}
}
}
sort(b+1, b+m+1);
b[0].p=INF+2;
for(i=1;i<=m+1;i++)
{
if(i==m+1||b[i].p!=b[i-1].p)
{
sol+=(s*(s-1)/2);
s=1;
}
else
{
s++;
}
}
printf("%d", sol);
}