Cod sursa(job #803586)

Utilizator Marius96Marius Gavrilescu Marius96 Data 27 octombrie 2012 21:02:02
Problema Triang Scor 100
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.21 kb
#include<cstdio>
#include<cmath>
#include<algorithm>

#define PI 3.141592653589793
#define EPSILON 1e-6

using std::sort;
using std::binary_search;

struct pt
{
	double x,y;

	pt()
		{
			x=y=0;
		}

	pt (double xx, double yy)
		{
			x=xx;
			y=yy;
		}

	pt negate ()const
		{
			return pt (-x,-y);
		}

	pt translate (pt o)const
		{
			return pt (x-o.x,y-o.y);
		}

	pt rotate (pt o, double angle)const
		{
			pt a=translate (o);
			pt r=pt (a.x*cos (angle)-a.y*sin (angle),a.x*sin (angle)+a.y*cos (angle));
			return r.translate (o.negate());
		}

	bool operator<(const pt p)const
		{
			if(fabs (x-p.x)<EPSILON){
				if(fabs (y-p.y)<EPSILON)
					return false;
				return y<p.y;
			}
			if(x<p.x)
				return true;
			if(x>p.x)
				return false;
			return y<p.y;
		}
}v[1505];

int main()
{
	freopen ("triang.in","r",stdin);
	freopen ("triang.out","w",stdout);

	int n;
	scanf ("%d",&n);
	for(int i=0;i<n;i++){
		double x,y;
		scanf ("%lf%lf",&x,&y);
		v[i]=pt (x,y);
	}

	sort (v,v+n);

	int r=0;
	for(int i=0;i<n;i++)
		for(int j=i+1;j<n;j++){
			pt p1=v[i].rotate (v[j],PI/3);
			pt p2=v[i].rotate (v[j],-PI/3);
			if(binary_search (v,v+n,p1))
				r++;
			if(binary_search (v,v+n,p2))
				r++;
		}

	printf ("%d",r/3);
	return 0;
}