Cod sursa(job #1073620)

Utilizator Cosmin1490Balan Radu Cosmin Cosmin1490 Data 6 ianuarie 2014 17:06:42
Problema Patrate 3 Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 2.3 kb
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <fstream>
#include <iterator>
#include <assert.h>
using namespace std;


const string file = "patrate3";

const string infile = file + ".in";
const string outfile = file + ".out";

const int INF = 0x3f3f3f3f;


struct Point
{
	double x;
	double y;
};


bool pred(const Point& a, const Point& b)
{
	if(a.x != b.x)
	{
		return a.x < b.x;
	}
	else
	{
		return a.y < b.y;
	}

}



bool Contains(vector<Point>& points, Point& toSearch)
{
	int left = 0;
	int right = points.size() - 1;

	while(left <= right)
	{
		int mid = (left + right) / 2;
		Point& midP = points[mid];
		if(abs(toSearch.x - midP.x) <= 0.000001 && abs(toSearch.y - midP.y) <= 0.000001)
		{
			return true;
		}

		bool comp = pred(toSearch, midP);
		if(comp == true)
		{
			right = mid - 1;
		}
		else
		{
			left = mid + 1;
		}

	}
	return false;

}

int main()
{
#ifdef ONLINE_JUDGE
	ostream &fout = cout;
	istream &fin = cin;
#else
	fstream fout(outfile.c_str(), ios::out);
	fstream fin(infile.c_str(), ios::in);
#endif	
	
	
	int N;
	fin >> N;
	vector<Point> points(N);
	for(int i = 0; i < N; i++)
	{
		fin >> points[i].x >> points[i].y;
	}

	sort(points.begin(), points.end(), pred);
	int Sol = 0;

	for(int i = 0; i < N; i++)
	{
		for(int j = i + 1; j < N; j++)
		{

			Point& a = points[i];
			Point& b = points[j];

			if(a.y < b.y)
			{

				Point mid;
				mid.x = (a.x + b.x)/2;
				mid.y = (a.y + b.y)/2;

				double dx = abs(mid.x - a.x);
				double dy = abs(mid.y - a.y);
			
				Point ul;
				ul.x = mid.x + dy;
				ul.y = mid.y - dx;
				Point lr;
				lr.x = mid.x - dy;
				lr.y = mid.y + dx;

				if(Contains(points, ul) && Contains(points, lr))
					Sol++;

			}

		}
	}

	fout << Sol << "\n";

#ifdef ONLINE_JUDGE
#else

	fin.close();
	fout.close();
#endif
}