Cod sursa(job #406790)

Utilizator titusuTitus C titusu Data 1 martie 2010 20:04:13
Problema Triang Scor 70
Compilator cpp Status done
Runda Arhiva de probleme Marime 1 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(int i=0;i<n-1;++i)
		for(int j=i+1;j<n;++j){
			if( binary_search(P.begin(),P.end(),Third(P[i],P[j])) )
				rez++;
			if( binary_search(P.begin(),P.end(),Third(P[j],P[i])) )
				rez++;
		}
	ofstream fout("triang.out");
	fout<<rez/3;
	return 0;
}