Pagini recente » Cod sursa (job #2575024) | Cod sursa (job #318451) | Cod sursa (job #2504661) | Cod sursa (job #2957425) | Cod sursa (job #499967)
Cod sursa(job #499967)
#include <cstdio>
#include <map>
#include <vector>
using namespace std;
#define fi first
#define se second
#define mp make_pair
FILE *in,*out;
map < pair<int,int> ,int > hash;
int x[1005],y[1005];
inline int abs(int x)
{
return x<0?-x:x;
}
int cmmdc(int x,int y)
{
if (!y)
return x;
return cmmdc(y,x%y);
}
int main()
{
int n,i,j,a,b,cntox=0,cntoy=0,rez=0,d;
map<pair<int,int>,int>::iterator it;
in=fopen("trapeze.in","r");
out=fopen("trapeze.out","w");
fscanf(in,"%d",&n);
for (i=1;i<=n;i++)
fscanf(in,"%d%d",&x[i],&y[i]);
for (i=1;i<=n;i++)
for (j=i+1;j<=n;j++)
{
if (x[i]==x[j])
{
cntoy++;
continue;
}
if (y[i]==y[j])
{
cntox++;
continue;
}
d=cmmdc(abs(x[i]-x[j]),abs(y[i]-y[j]));
a=(y[j]-y[i])/d;
b=(x[j]-x[i])/d;
hash[mp(a,b)]++;
}
rez=cntox * (cntox-1)/2 + cntoy*(cntoy-1)/2;
for (it=hash.begin();it!=hash.end();it++)
rez+=it->se*(it->se-1)/2;
fprintf(out,"%d\n",rez);
fclose(in);
fclose(out);
return 0;
}