Cod sursa(job #1153530)

Utilizator killer301Ioan Andrei Nicolae killer301 Data 25 martie 2014 15:53:54
Problema Patrate 3 Scor 100
Compilator cpp Status done
Runda Teme Pregatire ACM Unibuc 2013 Marime 1.18 kb
#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;
}