Cod sursa(job #2924343)

Utilizator lolismekAlex Jerpelea lolismek Data 30 septembrie 2022 11:01:03
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.7 kb
#include <iostream>
#include <fstream>
#include <cmath>
#include <set>

using namespace std;

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

const int N = 1500;

struct Point{
	double x, y;
}v[N + 1];

namespace Geometry{
	double dist(Point p1, Point p2){
		double dx = p1.x - p2.x, dy = p1.y - p2.y;
		return sqrt(dx * dx + dy * dy);
	}

	double area(Point p1, Point p2, Point p3){
		return p1.x * (p2.y - p3.y) + p2.x * (p3.y - p1.y) + p3.x * (p1.y - p2.y);
	}
}	

set <pair <long long, long long>> S;
set <pair <long long, long long>> E;

void Insert(pair <double, double> p){
	p.first *= (1000000000);
	p.first /= (1000000);

	p.second *= (1000000000);
	p.second /= (1000000);

	S.insert({(int)p.first, (int)p.second});
}

bool Find(pair <double, double> p){
	p.first *= (1000000000);
	p.first /= (1000000);

	p.second *= (1000000000);
	p.second /= (1000000);

	return S.find({p.first, p.second}) != S.end();
}

int main(){

	int n;
	fin >> n;

	for(int i = 1; i <= n; i++)
		fin >> v[i].x >> v[i].y, Insert({v[i].x, v[i].y});

	int ans = 0;
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j++){
			Point M = {v[i].x + v[j].x / 2, v[i].y + v[j].y / 2};

			Point p1 = v[i], p2 = v[j];

			if(p1.y > p2.y)
				swap(p1, p2);

			double dx, dy;
			dx = abs(p1.x - M.x);
			dy = abs(p1.y - M.y);

			if(p1.y < p2.y)
				dy = -dy;

			double ratio = sqrt(3); // (l * sqrt(3) / 2) / (l / 2) = sqrt(3)

			Point p3 = {M.x + (dy * ratio), M.y + (dx * ratio)};

			if(Find({p3.x, p3.y}))
				ans++;

			p3 = {M.x - (dy * ratio), M.y - (dx * ratio)};

			if(Find({p3.x, p3.y}))
				ans++;
		
		}

	fout << ans << '\n';

	return 0;
}