Cod sursa(job #406804)

Utilizator titusuTitus C titusu Data 1 martie 2010 20:13:47
Problema Triang Scor 80
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
using namespace std;
#include <fstream>
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#define NN 1505
#define EPS 0.001
#define PI 3.14159265

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;
	}
};

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;
	P.reserve(n);
	for(int i=0;i<n;++i){
		fin>>x>>y;
		P.push_back(punct(x,y));
	}
	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){
			if( binary_search(J+1,P.end(),Third(*I,*J)) )
				rez++;
			if( binary_search(J+1,P.end(),Third(*J,*I)) )
				rez++;
		}
	ofstream fout("triang.out");
	fout<<rez;
	return 0;
}