Find the coordinate that does not belong to any square | C ++ program for the above approach ; Function to find the point that is not a part of the side of a square ; Traverse each pair of coordinates ; Minimize x - coordinate in all the points except current point ; Maximize x - coordinate in all the points except the current point ; Minimize y - coordinate in all the points except current point ; Maximize y - coordinate in all the points except current point ; If x - coordinate matches with other same line ; If y coordinate matches with other same line ; Check if the condition for square exists or not ; Print the output ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; typedef long long ll ; #define fi  first NEW_LINE #define se  second NEW_LINE void findPoint ( int n , vector < pair < int , int > > p ) { for ( int i = 0 ; i < n * 4 + 1 ; ++ i ) { int x1 = 2e9 , x2 = -2e9 ; int y1 = 2e9 , y2 = -2e9 ; for ( int j = 0 ; j < n * 4 + 1 ; ++ j ) if ( i != j ) { x1 = min ( x1 , p [ j ] . fi ) ; x2 = max ( x2 , p [ j ] . fi ) ; y1 = min ( y1 , p [ j ] . se ) ; y2 = max ( y2 , p [ j ] . se ) ; } bool ok = 1 ; int c1 = 0 , c2 = 0 ; int c3 = 0 , c4 = 0 ; for ( int j = 1 ; j <= n * 4 + 1 ; ++ j ) if ( i != j ) { if ( ( p [ j ] . fi == x1 p [ j ] . fi == x2 ) || ( ( p [ j ] . se == y1 p [ j ] . se == y2 ) ) ) { if ( p [ j ] . fi == x1 ) ++ c1 ; if ( p [ j ] . fi == x2 ) ++ c2 ; if ( p [ j ] . se == y1 ) ++ c3 ; if ( p [ j ] . se == y2 ) ++ c4 ; } else ok = 0 ; } if ( ok && c1 >= n && c2 >= n && c3 >= n && c4 >= n && x2 - x1 == y2 - y1 ) { cout << p [ i ] . fi << " ▁ " << p [ i ] . se << " STRNEWLINE " ; } } } int main ( ) { int N = 2 ; vector < pair < int , int > > arr = { { 0 , 0 } , { 0 , 1 } , { 0 , 2 } , { 1 , 0 } , { 1 , 1 } , { 1 , 2 } , { 2 , 0 } , { 2 , 1 } , { 2 , 2 } } ; findPoint ( N , arr ) ; return 0 ; }