Cod sursa(job #406703)

Utilizator lorandCsorba Lorand-Alexandru lorand Data 1 martie 2010 19:04:30
Problema Triang Scor 20
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.09 kb
using namespace std;
#include<fstream>
#include<cmath>
#include<algorithm>
#define rad3 1.7320508076
struct punct
{
	double x;
	double y;
};
int N;
punct p[1505];
int comp(punct,punct);
int main()
{
	int i,j,k,nr=0;
	double x1,y1,x2,y2,xx,yy,lat,lat2,lat3;
	ifstream fin("triang.in");
	fin>>N;
	for(i=1;i<=N;++i)
		fin>>p[i].x>>p[i].y;
	sort(p+1,p+N+1,comp);
	for(i=1;i<=N;++i)
	{
		x1=p[i].x;
		y1=p[i].y;
		for(j=1;j<=N;++j)
			if(j!=i)
			{
				x2=p[j].x;
				y2=p[j].y;
				xx=x2-x1;
				yy=y2-y1;
				lat=sqrt(xx*xx+yy*yy);
				//h=(lat*lat*rad3)/2;
				for(k=1;k<=N;++k)
					if(k!=i && k!=j)
					{
						xx=p[k].x-x1;
						yy=p[k].y-y1;
						lat2=sqrt(xx*xx+yy*yy);
						xx=p[k].x-x2;
						yy=p[k].y-y2;
						lat3=sqrt(xx*xx+yy*yy);
						if(lat==lat2 && lat2==lat3)
							++nr;
						else
							if(abs(lat-lat2)<=0.001 && abs(lat2-lat3)<=0.001)
								++nr;
					}
			}
	}
	ofstream fout("triang.out");
	fout<<nr/6;
	return 0;
}
int comp(punct A,punct B)
{
	if(A.x<B.x)
		return 1;
	if(A.x==B.x)
	  if(A.y<B.y)
		return 1;
	return 0;
}