Cod sursa(job #2179030)

Utilizator flibiaVisanu Cristian flibia Data 19 martie 2018 21:48:40
Problema Patrate 3 Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.76 kb
#include <bits/stdc++.h>
#define mod 10001

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 2 * mod * (P.x + mod) + P.y + mod;
}

bool egal(double x, double y){
	return abs(x - y) < 0.00000001;
}

bool bs(point M){
	int st = 1, dr = n, mid;
	while(st <= dr){
		mid = st + dr >> 1;
//		if(egal(P[mid].x, M.x)){
//			if(egal(P[mid].y, M.y))
//				return 1;
//			if(P[mid].y <= M.y)
//				st = mid + 1;
//			else dr = mid - 1;
//			continue;
//		}
//		if(P[mid].x <= M.x)
//			st = mid + 1;
//		else dr = mid - 1;
		if(hsh(P[mid]) <= hsh(M))
			st = mid + 1;
		else dr = mid - 1;
	}
//	return 0;
//	if(hsh(P[dr]) == hsh(M)){
//	//	cout << M.x << ' ' << M.y << ' ' << P[dr].x << ' ' << P[dr].y << endl;
//	//	cout << (M.x == P[dr].x && M.y == P[dr].y) << endl;
//	//	cout << egal(M.x, P[dr].x) << endl;
//	//	cout << fixed << setprecision(3) << hsh(P[dr]) << ' ' << hsh(M) << endl;
//	}
	return egal(hsh(P[dr]), hsh(M));
//	return (M.x == P[dr].x && M.y == P[dr].y);
}

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++;
			//	cout << i << ' ' << j << endl;
			}
		}
	}
	out << cnt / 2;
	return 0;
}