Cod sursa(job #406867)

Utilizator titusuTitus C titusu Data 1 martie 2010 21:00:41
Problema Triang Scor 10
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.35 kb
using namespace std;
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#define NN 1505
#define EPS 0.001
#define PI 3.14159265
#define HSize 2521

const double aaa=(sqrt(19)-2)/3;

struct punct{
	double x,y;
	punct(){x=y=0;}
	punct(double X, double Y){ x=X, y=Y;}
	friend bool operator<(const punct &A, const punct &B){
		if(A.x+EPS< B.x)
			return 1;
		if(B.x+EPS < A.x)
			return 0;
		if(A.y+EPS<B.y)
			return 1;
		return 0;
	}
};

int HFunction(punct A){
	return int(abs(A.x+A.y)*aaa*HSize)%HSize;
}

punct Third(punct A, punct B){
	return punct(cos(PI/3)*(A.x-B.x) - sin(PI/3)*(A.y-B.y)+B.x, sin(PI/3)*(A.x-B.x) + cos(PI/3)*(A.y-B.y)+B.y);
}

int main(){
	int n;
	double x,y;
	ifstream fin("triang.in");
	fin>>n;
	vector<punct> P;
	set<punct> H[HSize];
	P.reserve(n);
	for(int i=0;i<n;++i){
		fin>>x>>y;
		punct A(x,y);
		P.push_back(A);
		H[HFunction(A)].insert(A);
	}
	sort(P.begin(),P.end());
	int rez=0;
	for(vector<punct>::iterator I=P.begin();I<P.end(); ++I)
		for(vector<punct>::iterator J=I+1;J<P.end();++J){
			punct  A = Third(*I,*J);
			int Index=HFunction(A);
			if( binary_search(H[Index].begin(),H[Index].end(),A) )
				rez++;
			A = Third(*J,*I);
			Index=HFunction(A);
			if( binary_search(H[Index].begin(),H[Index].end(),A) )
				rez++;
		}
	ofstream fout("triang.out");
	fout<<rez/3;
	return 0;
}