Cod sursa(job #3319730)

Utilizator DariuzzHackerPrime Dariuzz Data 2 noiembrie 2025 21:44:35
Problema Triang Scor 0
Compilator cpp-64 Status done
Runda Arhiva de probleme Marime 1.52 kb
#include <fstream>
#include<vector>
#include<cmath>
#include<algorithm>
#include<utility>
using namespace std;
ifstream cin("triang.in");
ofstream cout("triang.out");
bool egal(double a, double b, double eps = 1e-6) {
    return fabs(a - b) < eps;
}
bool triang (vector<pair<double,double> > &v , int poz , int n , pair<double,double> p1 , pair<double,double> p2 ){
       int st = poz , dr = n ; 
         while(st<=dr){
            int mij = (st+dr)/2;
              pair< double ,  double >  aux  = v[mij] ; 
                  double l1 , l2 , l3 ;
                  l1 = hypot(p1.first - p2.first , p1.second - p2.second ) ; 
                  l2 = hypot(p1.first - aux.first , p1.second - aux.second ) ; 
                  l3 = hypot(p2.first - aux.first , p2.second - aux.second ) ; 
                    if(egal(l1,l2) && egal(l2,l3) && egal(l1,l3)){
                          return true ; 
                    }else if(l1 < hypot(aux.first,aux.second)){
                        dr = mij - 1 ;  
                    }else{
                        st = mij + 1 ; 
                    }
         }
           return false ; 
}
int main() {
    int n;
    cin >> n;
    vector<pair<double, double > > v(n);
    for (int i = 0; i < n; i++)
        cin >> v[i].first >> v[i].second;

    int count = 0;
     sort( v.begin () , v.end () ) ; 
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
                if(triang(v,j+1,n,v[i],v[j]))
                  count ++ ; 
        }
    }

    cout << count  << "\n";
    return 0;
}