Check if any pair of semicircles intersect or not | C # 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
using System ; using System . Collections . Generic ; class GFG { class pair { public int first , second ; public pair ( int first , int second ) { this . first = first ; this . second = second ; } } static bool checkIntersection ( int [ ] arr , int N ) { List < pair > vec = new List < pair > ( ) ; 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 . Count ; i ++ ) { pair x = vec [ i ] ; for ( int j = 0 ; j < vec . Count ; j ++ ) { pair y = vec [ j ] ; bool cond1 = ( x . first < y . first && x . second < y . second && y . first < x . second ) ; bool 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 ) ) Console . Write ( " Yes " ) ; else Console . Write ( " No " ) ; } }