Pagini recente » Cod sursa (job #583408) | Cod sursa (job #2738864) | Cod sursa (job #3281317) | Cod sursa (job #1726987) | Cod sursa (job #1017637)
#include <fstream>
using namespace std;
ifstream cin("trapez.in");
ofstream cout("trapez.out");
short n, i, j;
int k, t, g, f;
int x[1001], y[1001], a[600001], b[600001];
void qsort(int a[], int b[], int st, int dr)
{
int i=st, j=dr;
int piv = a[(st+dr)/2];
while (i <= j)
{
while (a[i] < piv) i++;
while (a[j] > piv) j--;
if (i <= j)
{
swap(a[i],a[j]);
swap(b[i],b[j]);
i++;
j--;
}
}
if (st < j) qsort(a, b, st, j);
if (i < dr) qsort(a, b, i, dr);
}
int main()
{
cin>>n;
for(i=1; i<=n; i++) cin>>x[i]>>y[i];
for(i=1; i<n; i++)
for(j=i+1; j<=n; j++)
{
++k;
a[k]=y[i]-y[j];
b[k]=x[i]-x[j];
if(a[k]==0) k--, g++;
else if(b[k]==0) k--, f++;
}
t+=g*(g-1)/2+f*(f-1)/2;
qsort(a, b, 1, k);
for(i=1; i<k; i++)
for(j=i+1; j<=k; j++)
if(a[i] && a[j] && b[i] && b[j])
if(a[j]%a[i]==0 && b[j]%b[i]==0 && a[j]/a[i]==b[j]/b[i]) t++;
cout<<t;
return 0;
}