Pagini recente » Cod sursa (job #2140835) | Cod sursa (job #159107) | Cod sursa (job #2050973) | Cod sursa (job #370158) | Cod sursa (job #442188)
Cod sursa(job #442188)
#include<stdio.h>
struct structura{int x,y;};
structura p[1001],t;
float v[501501],aux;
int n,poz,nr,s;
void citire()
{
freopen("trapez.in","r",stdin);
int i;
scanf("%d",&n);
for(i=1;i<=n;i++)
scanf("%d%d",&p[i].x,&p[i].y);
}
void panta()
{
int i,j;
for(i=1;i<n;i++)
for(j=i+1;j<=n;j++)
{
poz++;
t.y=p[j].y-p[i].y;
t.x=p[j].x-p[i].x;
v[poz]=(float)t.y/t.x;
}
}
int divide(int p,int q)
{
int st,dr;float x;
st=p;dr=q;x=v[st];
while(st<dr)
{
while(x<=v[dr]&&st<dr)dr--;
v[st]=v[dr];
while(x>=v[st]&&st<dr)st++;
v[dr]=v[st];
}
v[st]=x;
}
void sortare(int p,int q)
{
int m; m=divide(p,q);
if(m-1>p) sortare(p,m-1);
if(m+1<q) sortare(m+1,q);
}
int main()
{
int i;
citire();
panta();
sortare(1,poz);
freopen("trapez.out","w",stdout);
aux=v[1];nr=1;
for(i=2;i<=poz;i++)
{
//printf("%f ",v[i]);
if(v[i]==aux)
nr++;
else
{
s=s+nr*(nr-1)/2;
nr=1;
aux=v[i];
}
}
printf("%d\n",s);
}