Cod sursa(job #2763997)

Utilizator popoviciAna16Popovici Ana popoviciAna16 Data 18 iulie 2021 15:27:27
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.11 kb
#include <iostream>
#include <fstream>
#include <set>
#include <cmath>
using namespace std;

ifstream fin ("triang.in");
ofstream fout ("triang.out");

const long double pi = 3.1415926535897932384626433832795;

struct punct
{
	double x, y;
	bool operator < (const punct &alt) const
	{
		if (abs (alt.x - x) > 1e-3)
		{
			if (abs (alt.y - y) > 1e-3)
				return alt.y < y;
			return 0;
		}
		return alt.x < x;
	}
} p[1501];

set <punct> s;

void calc3 (punct a, punct b, punct &c, punct &d)
{
	punct ba;
	long double r, alfa;
	
	ba.x = b.x - a.x;
	ba.y = b.y - a.y;
	
	r = sqrt (ba.x * ba.x + ba.y * ba.y);
	alfa = acos (ba.x / r);
	
	c.x = r * cos (alfa + pi/3) + a.x;
	c.y = r * sin (alfa + pi/3) + a.y;
	
	d.x = r * cos (alfa - pi/3) + a.x;
	d.y = r * sin (alfa - pi/3) + a.y;
}

int main()
{
	int n, i, j;
	punct pu, pd;
	int rasp = 0;
	fin >> n;
	for (i = 1; i<=n; i++)
	{
		fin >> p[i].x >> p[i].y;
		s.insert (p[i]);
	}
	
	for (i = 1; i<=n; i++)
		for (j = i+1; j<=n; j++)
		{
			calc3 (p[i], p[j], pu, pd);
			if (s.find (pu) != s.end())
				rasp++;
			if (s.find (pd) != s.end())
				rasp++;
		}
	
	fout << rasp / 3;
	return 0;
}