Cod sursa(job #411178)

Utilizator loginLogin Iustin Anca login Data 4 martie 2010 19:13:11
Problema Patrate 3 Scor 85
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.06 kb
# include <fstream>
# include <iostream>
# include <cmath>
# include <vector>
# include <algorithm>
# define PI 3.14159265
# define EPS 0.0001
using namespace std;
struct pct {
	double x, y;
	friend bool operator < (const pct &a, const pct &b)
	{
		if(a.x+EPS<b.x || (a.x-b.x>-EPS && a.x-b.x<EPS  && a.y+EPS<b.y))
			return 1;
		return 0;
	}
};
vector<pct>v;
int n, sol;

void read ()
{
	ifstream fin ("patrate3.in");
	pct p;
	fin>>n;
	for (int i=1;i<=n;i++)
	{
		fin>>p.x>>p.y;
		v.push_back(p);
	}
}

pct punct (pct a, pct b)
{
    pct p1;
	p1.x=cos(PI/2)*(b.x-a.x)-sin(PI/2)*(b.y-a.y)+a.x;
    p1.y=sin(PI/2)*(b.x-a.x)+cos(PI/2)*(b.y-a.y)+a.y;
    return p1;
}

void solve ()
{
	pct p1, p2, p;
	for (int i=0;i<n;i++)
		for (int j=i+1;j<n;j++)
		{
			p.x=(v[i].x+v[j].x)/2;
			p.y=(v[i].y+v[j].y)/2;
			p1=punct(p, v[i]);
			p2=punct(p, v[j]);
			if (binary_search(v.begin(), v.end(), p1))
				if (binary_search(v.begin(), v.end(), p2))
					sol++;
		}
}		
	
int main ()
{
	read();
	sort(v.begin(), v.end());
	solve ();
	ofstream fout ("patrate3.out");
	fout<<sol/2;
	return 0;
}