Total number of triplets ( A , B , C ) in which the points B and C are Equidistant to A | C ++ implementation to Find the total number of Triplets in which the points are Equidistant ; function to count such triplets ; Iterate over all the points ; Iterate over all points other than the current point ; Compute squared euclidean distance for the current point ; Compute nP2 that is n * ( n - 1 ) ; Return the final result ; Driver code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int numTrip ( vector < pair < int , int > > & points ) { int res = 0 ; for ( int i = 0 ; i < points . size ( ) ; ++ i ) { unordered_map < long , int > map ( points . size ( ) ) ; for ( int j = 0 ; j < points . size ( ) ; ++ j ) { if ( j == i ) continue ; int dy = points [ i ] . second - points [ j ] . second ; int dx = points [ i ] . first - points [ j ] . first ; int key = dy * dy ; key += dx * dx ; map [ key ] ++ ; } for ( auto & p : map ) res += p . second * ( p . second - 1 ) ; } return res ; } int main ( ) { vector < pair < int , int > > mat = { { 0 , 0 } , { 1 , 0 } , { 2 , 0 } } ; cout << numTrip ( mat ) ; return 0 ; }