Cod sursa(job #2779050)

Utilizator euyoTukanul euyo Data 2 octombrie 2021 16:45:39
Problema Triang Scor 100
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.09 kb
#include <fstream>
#include <iostream>
#include <cmath>
#include <set>

using namespace std;

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

const int MAXN = 1501; 
const double cos60 = 0.5;
const double sin60 = sqrt(3) / 2;
const double EPS = 1e-5;

struct pt {
  double x, y;

  bool operator < ( const pt &a ) const {
	if ( abs( a.x - (this -> x) ) > EPS ) {
	  return a.x > (this -> x);
	}
	if ( abs( a.y - (this -> y) ) > EPS ) {
	  return a.y > (this -> y);
	}
    return false;
  }
};

set<pt> s; 
pt v[MAXN];

pt get_point1( int i, int j ) {
  pt p1 = v[i], p2 = v[j], ret;

  ret.x = cos60 * (p1.x - p2.x) - sin60 * (p1.y - p2.y) + p2.x; 
  ret.y = sin60 * (p1.x - p2.x) + cos60 * (p1.y - p2.y) + p2.y;
  return ret;
}

int main() {
  int n, cnt;
  pt p;

  fin >> n;
  for ( int i = 1; i <= n; ++i ) {
	fin >> v[i].x >> v[i].y;
  }
  cnt = 0;
  for ( int i = 1; i <= n; ++i ) {
	for ( int j = 1; j < i; ++j ) {
	  p = get_point1(i, j);
	  if ( s.find(get_point1(i, j)) != s.end() ) {
        ++cnt;
	  }
	}
	s.insert( v[i] );
  }
  fout << cnt;
  fin.close();
  fout.close();
  return 0;
}