Check if any pair of semicircles intersect or not | Java program for the above approach ; Function to check if any pairs of the semicircles intersects or not ; Stores the coordinates of all the semicircles ; x and y are coordinates ; Store the minimum and maximum value of the pair ; Push the pair in vector ; Compare one pair with other pairs ; Generating the second pair ; Extract all the second pairs one by one ; 1 st condition ; 2 nd condition ; If any one condition is true ; If any pair of semicircles doesn 't exists ; Driver Code
import java . util . * ; class GFG { static class pair { int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static boolean checkIntersection ( int arr [ ] , int N ) { Vector < pair > vec = new Vector < > ( ) ; for ( int i = 0 ; i < N - 1 ; i ++ ) { int x = arr [ i ] , y = arr [ i + 1 ] ; int minn = Math . min ( x , y ) ; int maxx = Math . max ( x , y ) ; vec . add ( new pair ( minn , maxx ) ) ; } for ( int i = 0 ; i < vec . size ( ) ; i ++ ) { pair x = vec . elementAt ( i ) ; for ( int j = 0 ; j < vec . size ( ) ; j ++ ) { pair y = vec . elementAt ( j ) ; boolean cond1 = ( x . first < y . first && x . second < y . second && y . first < x . second ) ; boolean cond2 = ( y . first < x . first && y . second < x . second && x . first < y . second ) ; if ( cond1 cond2 ) { return true ; } } } return false ; } public static void main ( String [ ] args ) { int arr [ ] = { 0 , 15 , 5 , 10 } ; int N = arr . length ; if ( checkIntersection ( arr , N ) ) System . out . print ( " Yes " ) ; else System . out . print ( " No " ) ; } }