Cod sursa(job #2178953)

Utilizator flibiaVisanu Cristian flibia Data 19 martie 2018 20:45:58
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <bits/stdc++.h>

using namespace std;

ifstream in("patrate3.in");
ofstream out("patrate3.out");

struct point{
	double x, y;
};

int n, cnt;
point P[1010];

bool cmp(const point &a, const point &b){
	return (a.x == b.x ? a.y < b.y : a.x < b.x);	
}

double hsh(point P){
	return 1000000 * (P.x + 12000) + P.y;
}

bool bs(point M){
	int st = 1, dr = n, mid;
	while(st <= dr){
		mid = st + dr >> 1;
		if(hsh(P[mid]) <= hsh(M))
			st = mid + 1;
		else dr = mid - 1;
	}
	return hsh(P[dr]) == hsh(M);
}

int main(){
	in >> n;
	for(int i = 1; i <= n; i++)
		in >> P[i].x >> P[i].y;
	sort(P + 1, P + n + 1, cmp);
	for(int i = 1; i < n; i++){
		for(int j = i + 1; j <= n; j++){
			point M, A, B;
			M.x = (P[i].x + P[j].x) / 2;
			M.y = (P[i].y + P[j].y) / 2;
			double H = abs(P[j].y - M.y);
			double L = abs(P[j].x - M.x);
			if(P[j].y < P[i].y)
				H = -H;
			A.x = M.x - H;
			A.y = M.y + L;
			B.x = M.x + H;
			B.y = M.y - L;
			if(bs(A) && bs(B))
				cnt++;
		}
	}
	out << cnt / 2;
	return 0;
}