Cod sursa(job #2072114)

Utilizator eilerGabriel-Ciprian Stanciu eiler Data 21 noiembrie 2017 13:41:55
Problema Triang Scor 0
Compilator cpp Status done
Runda Arhiva de probleme Marime 1.04 kb
#include <fstream>
#include <cmath>
#include <algorithm>
using namespace std;

struct punct{
	double x, y;
};

int N, S;
punct P[1500];

bool compara(punct A, punct B){
	if (A.x==B.x)
		return A.y<B.y;
	return A.x<B.x;
}

bool egale(double a, double b){
	return fabs(a-b)<0.003;
}

double distanta(punct A, punct B){
	return sqrt((A.x-B.x)*(A.x-B.x)+(A.y-B.y)*(A.y-B.y));
}

bool gaseste(punct A, punct B, int i, double dist){
	int j, m;
	double dn, dm;

	j=N-1;
	while (i<=j){
		m=(i+j)/2;
		dn=distanta(A, P[m]); dm=distanta(B, P[m]);
		if (egale(dn, dm) && egale(dn, dist))
			return true;
		if (dn<dist)
			i=m+1;
		else
			j=m-1;
	}
	return false;
}

int main(){
	int i, j;

	ifstream fin ("triang.in");
	fin >> N;
	for (i=0; i<N; i++)
		fin >> P[i].x >> P[i].y;
	fin.close();

	sort(P, P+N, compara);

	for (i=0; i<N-2; i++)
		for (j=0; j<N-1; j++)
			if (gaseste(P[i], P[j], j+1, distanta(P[i], P[j])))
				S++;

	ofstream fout ("triang.out");
	fout << S << '\n';
	fout.close();

	return 0;
}