Pagini recente » Cod sursa (job #1278708) | Cod sursa (job #497931) | Cod sursa (job #1708401) | Cod sursa (job #914405) | Cod sursa (job #1153530)
#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
const double eps=1.e-4;
struct point
{
double x, y;
};
point a[1010];
bool egal(double a, double b)
{
return fabs(a-b)<eps;
}
bool bigger(double a, double b)
{
return a-b>=eps;
}
bool comp(point a, point b)
{
return bigger(b.x, a.x) || (egal(a.x, b.x) && bigger(b.y, a.y));
}
int n;
bool bin(point k)
{
int st=0, dr=n-1;
while(st<=dr)
{
int med=(st+dr)/2;
if(egal(k.x, a[med].x) && egal(k.y, a[med].y))
return 1;
if(comp(k, a[med]))
dr=med-1;
else st=med+1;
}
return 0;
}
bool square(point a,point b)
{
point x, y;
x.x=a.x+a.y-b.y;
x.y=a.y+b.x-a.x;
y.x=a.y+b.x-b.y;
y.y=b.x+b.y-a.x;
if(bin(x) && bin(y))
return 1;
return 0;
}
int main()
{
freopen("patrate3.in", "r", stdin);
freopen("patrate3.out", "w", stdout);
int nr=0;
scanf("%d", &n);
for(int i=0;i<n;i++)
{
double x, y;
scanf("%lf%lf", &x, &y);
a[i].x=x;a[i].y=y;
}
sort(a, a+n, comp);
for(int i=0;i<n;i++)
for(int j=i+1;j<n;j++)
{
nr+=square(a[i], a[j]);
}
printf("%d", nr/2);
return 0;
}