Pagini recente » Cod sursa (job #3203492) | Cod sursa (job #1142929) | Cod sursa (job #2181799) | Cod sursa (job #2025334) | Cod sursa (job #1981449)
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
const double eps=1.e-14;
const double INF=2.e-9;
struct POINT
{
double x,y;
};
double dist(POINT A, POINT B)
{
return sqrt((B.x-A.x)*(B.x-A.x)+(B.y-A.y)*(B.y-A.y));
}
bool vertical(POINT A,POINT B)
{
return (fabs(A.x-B.x)<eps);
}
bool same_point (POINT A,POINT B)
{
return fabs(A.x-B.x)<eps&&fabs(A.y-B.y)<eps;
}
double panta (POINT A,POINT B)
{
if(vertical(A,B))
return INF;
return (B.y-A.y)/(B.x-A.x);
}
vector <POINT>v;
vector <double>pante;
POINT aux;
int main()
{
freopen("trapez.in","r",stdin);
freopen("trapez.out","w",stdout);
int n,i,a,b,j,k=0,num=0,cnt;
double pan,old;
scanf("%d",&n);
for(i=1;i<=n;++i)
{
scanf("%d %d",&a,&b);
aux.x=a;
aux.y=b;
v.push_back(aux);
}
for(i=0;i<n-1;++i)
{
for(j=i+1;j<n;++j)
{
pan=panta(v[i],v[j]);
pante.push_back(pan);
}
}
sort(pante.begin(),pante.end());
i=num=cnt=0;
old=-1;
while(i<pante.size())
{
if(fabs(pante[i]-old)<eps)
{
i++;
cnt++;
}
else
{
k+=1LL*cnt*(cnt-1)/2;
cnt=1;old=pante[i];++i;
}
}
k+=1LL*cnt*(cnt-1)/2;
printf("%d",k);
return 0;
}