Cod sursa(job #2592093)

Utilizator mirceamaierean41Mircea Maierean mirceamaierean41 Data 1 aprilie 2020 02:00:31
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.25 kb
#include <fstream>
#include <map>
#include <cmath>
#include <vector>
#define x first
#define y second
using namespace std;

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

typedef pair <double, double> p;

vector <p> v;

int n;

map<p, p> mp;

inline double compute_distance(p a, p b)
{
	double _x = a.x - b.x, _y = a.y - b.y;
	return _x * _x + _y * _y;
}

int cnt;

int main()
{
	fin >> n;
	v.resize(n + 1);
	for (int i = 1; i <= n; ++i)
	{
		fin >> v[i].x >> v[i].y;
		map<p, p> crt = mp;
		for (int j = i - 1; j > 0; --j)
		{
			double x_m = (v[i].x + v[j].x) / 2, y_m = (v[i].y + v[j].y) / 2, pan = (v[i].x - v[j].x) / (v[i].y - v[j].y), d1 = compute_distance(v[i], v[j]);
			double d2 = 3 * d1 / 4;
			double panta = pan * pan - 1;
			d2 /= panta;
			d2 = sqrt(d2);
			double xc1 = d2 + x_m, xc2 = x_m - d2;
			double yc1 = pan * (xc1 - x_m) + y_m;
			double yc2 = pan * (xc2 - x_m) + y_m;
			if (crt.find({ xc1, yc1 }) != crt.end() && crt.find(v[j]) != crt.end())
			{
				++cnt;
				crt.erase(v[j]);
			}
			if (crt.find({ xc2, yc2 }) != crt.end() && crt.find(v[j]) != crt.end())
			{
				++cnt;
				crt.erase(v[j]);
			}
		}
		mp.insert({ v[i], {10001, 10001} });
	}
	fout << cnt << "\n";
	return 0;
}