Pagini recente » Monitorul de evaluare | Cod sursa (job #3333343) | Cod sursa (job #898271) | Cod sursa (job #605871) | Cod sursa (job #1647778)
#include <cstdio>
#include <algorithm>
using namespace std;
struct punct{int x,y;};
punct v[1001];
punct panta[1000005];
int modul(int a)
{
if(a<0)
a=a*(-1);
return a;
}
int cmmdc(int a, int b)
{
int r;
while(b!=0)
{
r=a%b;
a=b;
b=r;
}
return a;
}
bool cmp(punct a, punct b)
{
if(a.x<b.y)
return true;
else if(a.x>b.x)
return false;
else if(a.y<b.y)
return true;
else
return false;
}
int main(){
freopen("trapez.in" , "r" , stdin);
freopen("trapez.out" , "w" , stdout);
int n,i,j,k,cate,sol;
scanf("%d" , &n);
for(i=1; i<=n; i++)
scanf("%d%d" , &v[i].x, &v[i].y);
sort(v, v+1, cmp);
k=0;
for(i=1;i<=n;i++)
for(j=i+1;j<=n;j++)
{
k++;
panta[k].x=modul(v[i].x-v[j].x);
panta[k].y=modul(v[i].y-v[j].y);
panta[k].x=panta[k].x/cmmdc(panta[k].x, panta[k].y);
panta[k].y=panta[k].y/cmmdc(panta[k].x, panta[k].y);
}
sort(panta, panta+k+1, cmp);
cate=1; sol=0;
for(i=1; i<=k; i++)
if(panta[i].x==panta[i+1].x && panta[i].y==panta[i+1].y)
cate++;
else
{
sol=sol+cate*(cate-1)/2;
cate=1;
}
sol=sol+cate*(cate-1)/2;
printf("%d" , sol);
return 0;
}