Pagini recente » Cod sursa (job #1981557) | Cod sursa (job #208899) | Cod sursa (job #2713445) | Cod sursa (job #1356028) | Cod sursa (job #499984)
Cod sursa(job #499984)
#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> ,long long > 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,d;
long long rez=0,cntox=0,cntoy=0;
map<pair<int,int>,long long>::iterator it;
in=fopen("trapez.in","r");
out=fopen("trapez.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[j]-x[i]),abs(y[j]-y[i]));
a=(y[j]-y[i])/d;
b=(x[j]-x[i])/d;
if (a<0)
{
a*=-1;
b*=-1;
}
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,"%lld\n",rez);
fclose(in);
fclose(out);
return 0;
}